File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 11## HEAD (unreleased)
22
3+ - Safer NoMethodError annotation (https://github.com/zombocom/dead_end/pull/48 )
4+
35## 1.1.0
46
57- Annotate NoMethodError in non-production environments (https://github.com/zombocom/dead_end/pull/46 )
Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ module DeadEnd
6262# we can attempt to disable this behavior in a production context.
6363if !DeadEnd ::IsProduction . call
6464 class NoMethodError
65+ alias :original_to_s :to_s
66+
6567 def to_s
6668 return super if DeadEnd ::IsProduction . call
6769
@@ -91,8 +93,9 @@ def to_s
9193 message << $/
9294 message
9395 rescue => e
94- puts "DeadEnd Internal error: #{ e . message } "
95- puts "DeadEnd Internal backtrace: #{ e . backtrace } "
96+ puts "DeadEnd Internal error: #{ e . original_to_s } "
97+ puts "DeadEnd Internal backtrace:"
98+ puts backtrace . map { |l | " " + l } . join ( $/)
9699 super
97100 end
98101 end
Original file line number Diff line number Diff line change 44
55module DeadEnd
66 RSpec . describe "Requires with ruby cli" do
7+ it "does not get in an infinite loop when NoMethodError is raised internally" do
8+ Dir . mktmpdir do |dir |
9+ @tmpdir = Pathname ( dir )
10+ @script = @tmpdir . join ( "script.rb" )
11+ @script . write <<~'EOM'
12+ class DeadEnd::DisplayCodeWithLineNumbers
13+ def call
14+ raise NoMethodError.new("foo")
15+ end
16+ end
17+
18+ class Pet
19+ def initialize
20+ @name = "cinco"
21+ end
22+
23+ def call
24+ puts "Come here #{@neam.upcase}"
25+ end
26+ end
27+
28+ Pet.new.call
29+ EOM
30+
31+ out = `ruby -I#{ lib_dir } -rdead_end/auto #{ @script } 2>&1`
32+
33+ expect ( out ) . to include ( "DeadEnd Internal error: foo" )
34+ expect ( out ) . to include ( "DeadEnd Internal backtrace" )
35+ expect ( $?. success? ) . to be_falsey
36+ end
37+ end
38+
739 it "annotates NoMethodError" do
840 Dir . mktmpdir do |dir |
941 @tmpdir = Pathname ( dir )
You can’t perform that action at this time.
0 commit comments