Example:
require 'commandline'
class App < CommandLine::Application
def initialize
end
def main
raise 'foo'
end
end
results in
$ ruby test.rb
ERROR: foo
And here the problem starts: during development there will always be Exceptions thrown deep somewhere in my code and I need to see the stacktrace and not some mangled message.
Thanks to rampion, I'm now using this solution:
require 'commandline'
class App < CommandLine::Application
def initialize
end
def main
raise 'foo'
rescue Exception => e
puts format_like_real_exception e
end
def format_like_real_exception(e)
s = ''
b = e.backtrace
s << b.shift << ': ' << e.message << "\n"
b.each { |l| s << "\t" << l << "\n" }
s
end
end
Of course the formatter is not necessary, but I prefer it the way they're originally formatted.