Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (unreleased)

- Safer NoMethodError annotation (https://github.com/zombocom/dead_end/pull/48)

## 1.1.0

- Annotate NoMethodError in non-production environments (https://github.com/zombocom/dead_end/pull/46)
Expand Down
7 changes: 5 additions & 2 deletions lib/dead_end/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ module DeadEnd
# we can attempt to disable this behavior in a production context.
if !DeadEnd::IsProduction.call
class NoMethodError
alias :original_to_s :to_s

def to_s
return super if DeadEnd::IsProduction.call

Expand Down Expand Up @@ -91,8 +93,9 @@ def to_s
message << $/
message
rescue => e
puts "DeadEnd Internal error: #{e.message}"
puts "DeadEnd Internal backtrace: #{e.backtrace}"
puts "DeadEnd Internal error: #{e.original_to_s}"
puts "DeadEnd Internal backtrace:"
puts backtrace.map {|l| " " + l }.join($/)
super
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/integration/ruby_command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@

module DeadEnd
RSpec.describe "Requires with ruby cli" do
it "does not get in an infinite loop when NoMethodError is raised internally" do
Dir.mktmpdir do |dir|
@tmpdir = Pathname(dir)
@script = @tmpdir.join("script.rb")
@script.write <<~'EOM'
class DeadEnd::DisplayCodeWithLineNumbers
def call
raise NoMethodError.new("foo")
end
end

class Pet
def initialize
@name = "cinco"
end

def call
puts "Come here #{@neam.upcase}"
end
end

Pet.new.call
EOM

out = `ruby -I#{lib_dir} -rdead_end/auto #{@script} 2>&1`

expect(out).to include("DeadEnd Internal error: foo")
expect(out).to include("DeadEnd Internal backtrace")
expect($?.success?).to be_falsey
end
end

it "annotates NoMethodError" do
Dir.mktmpdir do |dir|
@tmpdir = Pathname(dir)
Expand Down