Skip to content

Commit 80fe64a

Browse files
committed
fix: catch all exceptions including those from Ruby::Box isolation
Use 'rescue Exception' with explicit re-raise of system exceptions (SystemExit, Interrupt, SignalException) to ensure all errors are caught and displayed properly, including exceptions from Ruby::Box whose classes don't match the outer world's StandardError hierarchy.
1 parent e4e8343 commit 80fe64a

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

lib/liquid/spec/cli/eval.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def self.run_eval(options, adapter_file)
228228
show_contribution_message(has_difference)
229229

230230
exit(1) unless test_passed
231-
rescue => e
231+
rescue SystemExit, Interrupt, SignalException
232+
raise
233+
rescue Exception => e
232234
print_error(e, hint, verbose, spec_data)
233235

234236
if compare_mode
@@ -395,7 +397,9 @@ def self.run_reference_implementation(template_source, assigns, verbose)
395397
output = template.render(context)
396398

397399
[output, nil]
398-
rescue => e
400+
rescue SystemExit, Interrupt, SignalException
401+
raise
402+
rescue Exception => e
399403
[nil, e]
400404
end
401405

lib/liquid/spec/cli/runner.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,14 @@ def self.run_specs_frozen(config, options)
233233
errors = 0
234234

235235
suite_specs.each do |spec|
236-
result = run_single_spec(spec, config)
236+
begin
237+
result = run_single_spec(spec, config)
238+
rescue SystemExit, Interrupt, SignalException
239+
raise
240+
rescue Exception => e
241+
# Catch all exceptions including those from Ruby::Box isolation
242+
result = { status: :error, error: e }
243+
end
237244

238245
case result[:status]
239246
when :pass
@@ -380,7 +387,10 @@ def self.run_specs_compare(config, options)
380387
suite_specs.each do |spec|
381388
begin
382389
result = compare_single_spec(spec, config)
383-
rescue StandardError, Exception => e
390+
rescue SystemExit, Interrupt, SignalException
391+
raise
392+
rescue Exception => e
393+
# Catch all exceptions including those from Ruby::Box isolation
384394
result = { status: :error, error: e }
385395
end
386396

@@ -555,7 +565,9 @@ def self.run_reference_spec(spec, _compile_options, assigns, render_options)
555565

556566
ref_result = template.render(context)
557567
[ref_result, nil]
558-
rescue => e
568+
rescue SystemExit, Interrupt, SignalException
569+
raise
570+
rescue Exception => e
559571
[nil, e]
560572
end
561573

@@ -566,7 +578,9 @@ def self.run_adapter_spec(spec, compile_options, assigns, render_options)
566578
template = LiquidSpec.do_compile(spec.template, compile_options)
567579
template.name = spec.template_name if spec.template_name && template.respond_to?(:name=)
568580
adapter_result = LiquidSpec.do_render(template, assigns, render_options)
569-
rescue StandardError => e
581+
rescue SystemExit, Interrupt, SignalException
582+
raise
583+
rescue Exception => e
570584
adapter_error = e
571585
end
572586
[adapter_result, adapter_error]

0 commit comments

Comments
 (0)