Skip to content

Commit

Permalink
Merge pull request #402 from nanoc/bug/see-crash-log-in-crash-log
Browse files Browse the repository at this point in the history
Remove "see full crash log" line from crash log
  • Loading branch information
denisdefreyne committed Mar 16, 2014
2 parents ed1c609 + 7d48fa6 commit 8a8d398
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/nanoc/cli/error_handler.rb
Expand Up @@ -293,13 +293,15 @@ def write_compilation_stack(stream, error, params = {})
end

def write_stack_trace(stream, error, params = {})
is_verbose = params.fetch(:verbose, false)

write_section_header(stream, 'Stack trace', params)

count = params[:verbose] ? -1 : 10
count = is_verbose ? -1 : 10
error.backtrace[0...count].each_with_index do |item, index|
stream.puts " #{index}. #{item}"
end
if error.backtrace.size > count
if !is_verbose && error.backtrace.size > count
stream.puts " ... #{error.backtrace.size - count} more lines omitted. See full crash log for details."
end
end
Expand Down
32 changes: 32 additions & 0 deletions test/cli/test_error_handler.rb
Expand Up @@ -29,4 +29,36 @@ def test_resolution_for_with_not_load_error
assert_nil @handler.send(:resolution_for, error)
end

def test_write_stack_trace_verbose
error = new_error(20)

stream = StringIO.new
@handler.send(:write_stack_trace, stream, error, :verbose => false)
assert_match(/See full crash log for details./, stream.string)

stream = StringIO.new
@handler.send(:write_stack_trace, stream, error, :verbose => false)
assert_match(/See full crash log for details./, stream.string)

stream = StringIO.new
@handler.send(:write_stack_trace, stream, error, :verbose => true)
refute_match(/See full crash log for details./, stream.string)
end

def new_error(amount_factor)
backtrace_generator = lambda do |af|
if af == 0
raise "finally!"
else
backtrace_generator.call(af - 1)
end
end

begin
backtrace_generator.call(amount_factor)
rescue => e
return e
end
end

end

0 comments on commit 8a8d398

Please sign in to comment.