Edgewall Software
Modify

#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:

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):  
    401401        directory."""
    402402        try:
    403403            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))
    407404        except Exception, e:
    408405            raise TracError(_("No Trac environment found at %(path)s\n"
    409406                              "%(e)s", path=self.path, e=e))
     407        if tag != _VERSION:
     408            raise TracError(_("Unknown Trac environment type '%(type)s'",
     409                              type=tag))
    410410
    411411    def get_db_cnx(self):
    412412        """Return a database connection from the connection pool

I'll add test coverage.

Attachments (0)

Change History (6)

comment:1 by Ryan J Ollos, 17 months ago

Proposed changes: [66d0b09b9/rjollos.git].

comment:2 by Jun Omae, 17 months 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):  
    403403            tag = read_file(os.path.join(self.path, 'VERSION')).splitlines()[0]
    404404        except Exception, e:
    405405            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)))
    407408        if tag != _VERSION:
    408409            raise TracError(_("Unknown Trac environment type '%(type)s'",
    409410                              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 Jun Omae, 17 months 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 Ryan J Ollos, 17 months ago

Milestone: 1.0.181.2.4

Minor issue so I'll fix only on 1.2-stable and higher.

comment:6 by Ryan J Ollos, 17 months ago

Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r16782, merged in r16783.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.