Edgewall Software
Modify

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#10408 closed enhancement (fixed)

trac-admin: more descriptive error message on invalid env path

Reported by: anatoly techtonik <techtonik@…> Owned by: Remy Blank
Priority: normal Milestone: 1.0
Component: admin/console Version: 0.12.2
Severity: minor Keywords: bitesized
Cc: Thijs Triemstra Branch:
Release Notes:
API Changes:
Internal Changes:

Description

When wrong path is specified to trac-admin you get the following confusing message:

$ trac-admin /var/trac upgrade
Error: Command not found

Attachments (1)

ticket_10408.patch (1.0 KB ) - added by coelhudo@… 12 years ago.
Improving error message

Download all attachments as: .zip

Change History (13)

comment:1 by Remy Blank, 13 years ago

Keywords: bitesized added
Milestone: next-major-0.1X
Type: defectenhancement

Yes, this could be improved.

comment:2 by Thijs Triemstra, 13 years ago

Cc: Thijs Triemstra added

comment:3 by coelhudo@…, 13 years ago

I just finish to read the HowToContribute section, then I downloaded and setup the enviroment. Then I decided to fix a bitesized ticket.

I cloned the repository and I ran the "trac-admin" command and I saw a different message:

trac-admin /var/trac upgrade
Error: IOError: [Errno 2] No such file or directory: '/var/trac/VERSION'

This error message need to be improved?

comment:4 by anatoly techtonik <techtonik@…>, 13 years ago

I see that the error message is improved already, but it can give an additional user-friendly hint.

comment:5 by Remy Blank, 13 years ago

The message is not ideal, as it references /var/trac/VERSION and not the path entered on the command line. Ideally, we should check for the existence of the environment path and show a message if it doesn't exist, even before trying to open it.

by coelhudo@…, 12 years ago

Attachment: ticket_10408.patch added

Improving error message

comment:6 by coelhudo@…, 12 years ago

Trying to improve this message through a clear message.

comment:7 by Christian Boos, 12 years ago

Milestone: next-major-0.1X1.0
Owner: set to Christian Boos
Severity: normalminor

Well, the message is misleading as there's no such environment variable VERSION. We're talking about the file <trac-env>/VERSION here!

comment:8 by anatoly techtonik <techtonik@…>, 12 years ago

  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    index 468e37d..ee0adfc 100644
    a b class Environment(Component, ComponentManager):  
    364364    def verify(self):
    365365        """Verify that the provided path points to a valid Trac environment
    366366        directory."""
    367         with open(os.path.join(self.path, 'VERSION'), 'r') as fd:
    368             assert fd.read(26) == 'Trac Environment Version 1'
     367
     368        try:
     369            with open(os.path.join(self.path, 'VERSION'), 'r') as fd:
     370                assert fd.read(26) == 'Trac Environment Version 1'
     371        except:
     372            raise TracError(_('Trac environment is not found on the given path:\n  %(enviroment_path)s.',
     373                              enviroment_path = os.path.join(self.path)))
    369374
    370375    def get_db_cnx(self):
    371376        """Return a database connection from the connection pool

comment:9 by Remy Blank, 12 years ago

Could you also please replace the use of assert? It becomes a no-op when compiled with -O. And use read() instead of read(26), so that we differentiate between 'Trac Environment Version 1' and 'Trac Environment Version 13'. Actually, the best would be to use trac.util.read_file().

in reply to:  8 comment:10 by anatoly techtonik <techtonik@…>, 12 years ago

That's not my patch, bit I can edit it no problem (somebody need to insert from trac.util import read_file:

  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    index 468e37d..ee0adfc 100644
    a b class Environment(Component, ComponentManager):  
    364364    def verify(self):
    365365        """Verify that the provided path points to a valid Trac environment
    366366        directory."""
    367         with open(os.path.join(self.path, 'VERSION'), 'r') as fd:
    368             assert fd.read(26) == 'Trac Environment Version 1'
     367
     368        try:
     369            if not read_file(os.path.join(self.path, 'VERSION')).startswith('Trac Environment Version 1'):
     370                raise TracError(_('Bad VERSION content.'))
     371        except:
     372            raise TracError(_('Trac environment is not found on the given path:\n  %(enviroment_path)s.',
     373                              enviroment_path = self.path))
    369374
    370375    def get_db_cnx(self):
    371376        """Return a database connection from the connection pool

comment:11 by Remy Blank, 12 years ago

Resolution: fixed
Status: newclosed

Fixed in [11073].

comment:12 by Remy Blank, 12 years ago

Owner: changed from Christian Boos to Remy Blank

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank 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.