Skip to content

Commit

Permalink
Merge pull request aeolus-incubator#10 from cwolferh/exception_handling
Browse files Browse the repository at this point in the history
Catch all exceptions at the top level (but don't bury them!)
  • Loading branch information
jguiditta committed Dec 7, 2012
2 parents 9c759ba + ce3506a commit 0bcd6a0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bin/aeolus
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#!/usr/bin/env ruby

require 'aeolus_cli/main'
AeolusCli::Main.start

begin
AeolusCli::Main.start
rescue Exception => ex
puts "Error: #{ex.message}"
fname = "/tmp/aeolus-cli-trace-#{Process.pid}.log"
the_stack_trace = ex.backtrace().join($/)
begin
# it is very unlikely writing to /tmp would fail, but
# wrap this so we don't bury the original exception
f = File.open(fname, "w")
puts "For further debugging information, see #{fname}"
f.puts the_stack_trace
f.close
rescue
puts "Was unable to write to the following stack trace to #{fname}:"
puts the_stack_trace
end
end
2 changes: 2 additions & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Default terminal width we use for cucumber tests
default: THOR_COLUMNS=118
9 changes: 9 additions & 0 deletions features/exceptions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Exception Handling

Scenario: Garbage URL Input
When I run `aeolus provider list --conductor-url=http://444.444.444.444:444/api --username=test --password=test`
Then the aeolus command should write the stack trace to file
And the output should contain:
"""
Error:
"""
11 changes: 11 additions & 0 deletions features/step_definitions/exceptions_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'aruba/api'

Then /^the aeolus command should write the stack trace to file$/ do
/For further debugging information, see (\/tmp\/aeolus-cli-trace-\d+.log)/ =~
all_output
trace_filename = Regexp.last_match(1)

# The last line in the stack trace file will look something like
# ....../thor-cli/bin/aeolus:6:in `<main>'
check_file_content(trace_filename, /bin\/aeolus:\d+:in `<main>/, true)
end

0 comments on commit 0bcd6a0

Please sign in to comment.