[Rubygems-developers] $VERBOSE and error messages

Gavin Sinclair gsinclair at soyabean.com.au
Sun Apr 18 15:58:54 EDT 2004


In order to provide some consistency to error message output, I wanted
to take the following approach:

 1. Allow the user to specify --verbose to get more error details.

 2. When an exception is caught, display a brief message.  Include the
    backtrace iff the user has specified --verbose.


I just added (but didn't commit) this code to the option parser in bin/gem:

      op.on('-v', '--verbose', "Give more verbose output in error conditions") {
        $VERBOSE = true
      }

And I have already added (and committed) this code to the "build" operation:

  rescue Gem::Exception => err
    puts "Operation failed: #{err}"
    puts err.backtrace if $VERBOSE
  rescue => err
    puts "Unexpected error: #{err}"
    puts "Details:"
    puts err.backtrace
    exit!

Notice that a *gem*-related exception just gets a brief error message
by default, but an unexpected error (e.g. NameError) will get the full
gory details (needed for tracking down the cause).
    
I like this approach, but would like to solicit comment.  In
particular, should we be using the existing variable $VERBOSE or not?

Cheers,
Gavin



More information about the Rubygems-developers mailing list