#13061 closed defect (fixed)
'Environment not found' message when environment is wrong version
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.2.4 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Improved error message when environment is incorrect version. |
||
API Changes: | |||
Internal Changes: |
Description
If environment has incorrect version, the browser message is:
Error TracError: No Trac environment found at /Users/rjollos/Documents/Workspace/trac-dev/tracenvs/proj-1.0 Unknown Trac environment type 'Trac Environment Version 2'
I think we should reorder the exception handling so the message is:
Error TracError: Unknown Trac environment type 'Trac Environment Version 2'
-
trac/env.py
diff --git a/trac/env.py b/trac/env.py index 8c464c092..c3d280952 100644
a b class Environment(Component, ComponentManager): 401 401 directory.""" 402 402 try: 403 403 tag = read_file(os.path.join(self.path, 'VERSION')).splitlines()[0] 404 if tag != _VERSION:405 raise Exception(_("Unknown Trac environment type '%(type)s'",406 type=tag))407 404 except Exception, e: 408 405 raise TracError(_("No Trac environment found at %(path)s\n" 409 406 "%(e)s", path=self.path, e=e)) 407 if tag != _VERSION: 408 raise TracError(_("Unknown Trac environment type '%(type)s'", 409 type=tag)) 410 410 411 411 def get_db_cnx(self): 412 412 """Return a database connection from the connection pool
I'll add test coverage.
Attachments (0)
Change History (7)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
When the VERSION
file is empty, I get list index out of range
. I couldn't understand the error.
Error TracError: No Trac environment found at /dev/shm/tracenv-empty list index out of range
I consider class name of the exception should be printed.
-
trac/env.py
diff --git a/trac/env.py b/trac/env.py index c3d280952..73cda44e3 100644
a b class Environment(Component, ComponentManager): 403 403 tag = read_file(os.path.join(self.path, 'VERSION')).splitlines()[0] 404 404 except Exception, e: 405 405 raise TracError(_("No Trac environment found at %(path)s\n" 406 "%(e)s", path=self.path, e=e)) 406 "%(e)s", 407 path=self.path, e=exception_to_unicode(e))) 407 408 if tag != _VERSION: 408 409 raise TracError(_("Unknown Trac environment type '%(type)s'", 409 410 type=tag))
The original IndexError
would be fixed by the following patch:
- tag = read_file(os.path.join(self.path, 'VERSION')).splitlines()[0] + with open(os.path.join(self.path, 'VERSION'), 'r') as f: + tag = f.readline().rstrip('\n')
comment:3 by , 6 years ago
trac/tests/env.py has a syntax error with Python 2.5, at least.
File "/dev/shm/66d0b09b9e7fb9a8df3d8d393bde461142348753/py25-sqlite/trac/tests/env.py", line 78 except TracError as e: ^ SyntaxError: invalid syntax
comment:4 by , 6 years ago
Milestone: | 1.0.18 → 1.2.4 |
---|
Minor issue so I'll fix only on 1.2-stable and higher.
comment:5 by , 6 years ago
Added comment:2 changes: log:rjollos.git:t13061_environment_wrong_version.1.
comment:6 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Proposed changes: [66d0b09b9/rjollos.git].