Skip to content

Fix exception handling (in_sqs.rb)#43

Open
JamesJJ wants to merge 1 commit intoixixi:masterfrom
JamesJJ:20180510-jamesjj-exception-handling
Open

Fix exception handling (in_sqs.rb)#43
JamesJJ wants to merge 1 commit intoixixi:masterfrom
JamesJJ:20180510-jamesjj-exception-handling

Conversation

@JamesJJ
Copy link
Contributor

@JamesJJ JamesJJ commented May 10, 2018

We found this:

2018-05-10 12:34:59 +0000 [error]: #0 Unexpected error raised. Stopping the timer.
 title=:in_sqs_run_periodic_timer
 error_class=NoMethodError
 error="undefined method `backtrace' for nil:NilClass"

This PR updates the exception handling to prevent exception inside rescue (and so prevent timer being stopped)

Proof of concept in irb:

Before:

$ irb
irb(main):001:0> begin; puts File.join(nil, "hey"); rescue   # Cause some exception
irb(main):002:1> puts $ERROR_INFO.to_s
irb(main):003:1> puts $ERROR_INFO.backtrace
irb(main):004:1> end

NoMethodError: undefined method `backtrace' for nil:NilClass
	from (irb):3:in `rescue in irb_binding'
	from (irb):1
	from /usr/local/bin/irb:11:in `<main>'
irb(main):005:0> ## Exception inside rescue T_T

After:

irb(main):001:0> begin; puts File.join(nil, "hey"); rescue => ex   # Cause some exception
irb(main):002:1> puts ex.to_s
irb(main):003:1> puts ex.backtrace
irb(main):004:1> end
no implicit conversion of nil into String
(irb):1:in `join'
(irb):1:in `irb_binding'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/workspace.rb:87:in `eval'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/workspace.rb:87:in `evaluate'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/context.rb:381:in `evaluate'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:493:in `block (2 levels) in eval_input'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:627:in `signal_status'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:490:in `block in eval_input'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in `loop'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in `catch'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:489:in `eval_input'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:430:in `block in run'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:429:in `catch'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:429:in `run'
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/irb.rb:385:in `start'
/usr/local/bin/irb:11:in `<main>'
=> nil
irb(main):005:0>  ## Successfully rescued

@payxn
Copy link

payxn commented Dec 30, 2025

Hello,

Is this planned to be merged ? @ixixi I had the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants