@@ -45,15 +45,26 @@ def method_that_raises
45
45
end
46
46
47
47
def raise_nested_exceptions
48
+ raise_nested_exceptions_third
49
+ end
50
+
51
+ def raise_nested_exceptions_first
48
52
raise "First error"
53
+ end
54
+
55
+ def raise_nested_exceptions_second
56
+ raise_nested_exceptions_first
49
57
rescue
50
- begin
51
- raise "Second error"
52
- rescue
53
- raise "Third error"
54
- end
58
+ raise "Second error"
55
59
end
56
60
61
+ def raise_nested_exceptions_third
62
+ raise_nested_exceptions_second
63
+ rescue
64
+ raise "Third error"
65
+ end
66
+
67
+
57
68
def call ( env )
58
69
env [ "action_dispatch.show_detailed_exceptions" ] = @detailed
59
70
req = ActionDispatch ::Request . new ( env )
@@ -641,29 +652,67 @@ def self.build_app(app, *args)
641
652
Information for: RuntimeError (Third error):
642
653
MSG
643
654
644
- assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 2 ] . lines [ 0 ..2 ] . join
645
- \\ A.*in `rescue in rescue in raise_nested_exceptions'
646
- .*in `rescue in raise_nested_exceptions'
647
- .*in `raise_nested_exceptions'
648
- REGEX
649
-
650
- assert_includes ( paragraphs [ 3 ] , <<~MSG . strip )
651
- Information for cause: RuntimeError (Second error):
652
- MSG
653
-
654
- assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 4 ] . lines [ 0 ..1 ] . join
655
- \\ A.*in `rescue in raise_nested_exceptions'
656
- .*in `raise_nested_exceptions'
657
- REGEX
658
-
659
-
660
- assert_includes ( paragraphs [ 5 ] , <<~MSG . strip )
661
- Information for cause: RuntimeError (First error):
662
- MSG
663
-
664
- assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 6 ] . lines [ 0 ]
665
- \\ A.*in `raise_nested_exceptions'
666
- REGEX
655
+ if RUBY_VERSION >= "3.4"
656
+ # Changes to the format of exception backtraces
657
+ # https://bugs.ruby-lang.org/issues/16495 (use single quote instead of backtrace)
658
+ # https://bugs.ruby-lang.org/issues/20275 (don't have entry for rescue in)
659
+ # And probably more, they now show the class too
660
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 2 ]
661
+ \\ A.*in '.*raise_nested_exceptions_third'
662
+ .*in '.*raise_nested_exceptions'
663
+ REGEX
664
+
665
+ assert_includes ( paragraphs [ 3 ] , <<~MSG . strip )
666
+ Information for cause: RuntimeError (Second error):
667
+ MSG
668
+
669
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 4 ]
670
+ \\ A.*in '.*raise_nested_exceptions_second'
671
+ .*in '.*raise_nested_exceptions_third'
672
+ .*in '.*raise_nested_exceptions'
673
+ REGEX
674
+
675
+
676
+ assert_includes ( paragraphs [ 5 ] , <<~MSG . strip )
677
+ Information for cause: RuntimeError (First error):
678
+ MSG
679
+
680
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 6 ]
681
+ \\ A.*in '.*raise_nested_exceptions_first'
682
+ .*in '.*raise_nested_exceptions_second'
683
+ .*in '.*raise_nested_exceptions_third'
684
+ .*in '.*raise_nested_exceptions'
685
+ REGEX
686
+ else
687
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 2 ]
688
+ \\ A.*in `rescue in raise_nested_exceptions_third'
689
+ .*in `raise_nested_exceptions_third'
690
+ .*in `raise_nested_exceptions'
691
+ REGEX
692
+
693
+ assert_includes ( paragraphs [ 3 ] , <<~MSG . strip )
694
+ Information for cause: RuntimeError (Second error):
695
+ MSG
696
+
697
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 4 ]
698
+ \\ A.*in `rescue in raise_nested_exceptions_second'
699
+ .*in `raise_nested_exceptions_second'
700
+ .*in `raise_nested_exceptions_third'
701
+ .*in `raise_nested_exceptions'
702
+ REGEX
703
+
704
+
705
+ assert_includes ( paragraphs [ 5 ] , <<~MSG . strip )
706
+ Information for cause: RuntimeError (First error):
707
+ MSG
708
+
709
+ assert_match Regexp . new ( <<~REGEX . strip ) , paragraphs [ 6 ]
710
+ \\ A.*in `raise_nested_exceptions_first'
711
+ .*in `raise_nested_exceptions_second'
712
+ .*in `raise_nested_exceptions_third'
713
+ .*in `raise_nested_exceptions'
714
+ REGEX
715
+ end
667
716
end
668
717
669
718
test "display backtrace when error type is SyntaxError" do
@@ -783,28 +832,28 @@ def self.build_app(app, *args)
783
832
# Possible Ruby 3.4-dev bug: https://bugs.ruby-lang.org/issues/19117#note-45
784
833
# assert application trace refers to line that raises the last exception
785
834
assert_select "#Application-Trace-0" do
786
- assert_select "code a:first" , %r{in '.*raise_nested_exceptions '}
835
+ assert_select "code a:first" , %r{in '.*raise_nested_exceptions_third '}
787
836
end
788
837
789
838
# assert the second application trace refers to the line that raises the second exception
790
839
assert_select "#Application-Trace-1" do
791
- assert_select "code a:first" , %r{in '.*raise_nested_exceptions '}
840
+ assert_select "code a:first" , %r{in '.*raise_nested_exceptions_second '}
792
841
end
793
842
else
794
843
# assert application trace refers to line that raises the last exception
795
844
assert_select "#Application-Trace-0" do
796
- assert_select "code a:first" , %r{in [`']rescue in rescue in .*raise_nested_exceptions '}
845
+ assert_select "code a:first" , %r{in [`']rescue in .*raise_nested_exceptions_third '}
797
846
end
798
847
799
848
# assert the second application trace refers to the line that raises the second exception
800
849
assert_select "#Application-Trace-1" do
801
- assert_select "code a:first" , %r{in [`']rescue in .*raise_nested_exceptions '}
850
+ assert_select "code a:first" , %r{in [`']rescue in .*raise_nested_exceptions_second '}
802
851
end
803
852
end
804
853
805
854
# assert the third application trace refers to the line that raises the first exception
806
855
assert_select "#Application-Trace-2" do
807
- assert_select "code a:first" , %r{in [`'].*raise_nested_exceptions '}
856
+ assert_select "code a:first" , %r{in [`'].*raise_nested_exceptions_first '}
808
857
end
809
858
end
810
859
end
0 commit comments