Skip to content

Commit

Permalink
don't assume "file:line:in method" format for backtrace lines (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Somerville committed Dec 11, 2012
1 parent eb925dd commit cc80f86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/better_errors/stack_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def self.from_exception(exception)
idx_offset = 0
list = exception.backtrace.each_with_index.map do |frame, idx|
frame_binding = exception.__better_errors_bindings_stack[idx - idx_offset]
md = /\A(?<file>.*):(?<line>\d*):in `(?<name>.*)'\z/.match(frame)
md = /\A(?<file>.*):(?<line>\d*)(:in `(?<name>.*)')?\z/.match(frame)

# prevent mismatching frames in the backtrace with the binding stack
if frame_binding and frame_binding.eval("__FILE__") != md[:file]
Expand Down
14 changes: 14 additions & 0 deletions spec/better_errors/stack_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,19 @@ module BetterErrors
frames.first.filename.should == "my_file.rb"
frames.first.line.should == 123
end

it "should not blow up if no method name is given" do
error = StandardError.new

error.stub!(:backtrace).and_return(["foo.rb:123"])
frames = StackFrame.from_exception(error)
frames.first.filename.should == "foo.rb"
frames.first.line.should == 123

error.stub!(:backtrace).and_return(["foo.rb:123: this is an error message"])
frames = StackFrame.from_exception(error)
frames.first.filename.should == "foo.rb"
frames.first.line.should == 123
end
end
end

0 comments on commit cc80f86

Please sign in to comment.