Last active
November 15, 2016 22:50
-
-
Save CGamesPlay/32584fcb5bead60ead99e0aa9a94b778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'byebug/core' | |
rescue LoadError | |
return | |
end | |
module Byebug | |
def self.byebug_on_error | |
unless started? | |
self.mode = :attached | |
start | |
run_init_script | |
end | |
old_value = post_mortem? | |
self.post_mortem = true | |
begin | |
yield | |
rescue Exception => ex | |
ContinueCommand.allow_in_post_mortem = true | |
Byebug::Context.interface.errmsg("#{ex.class.name}: #{ex.message}") | |
handle_post_mortem | |
ContinueCommand.allow_in_post_mortem = false | |
raise ex | |
ensure | |
self.post_mortem = old_value | |
stop if stoppable? | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'byebug' | |
require_relative './patch' | |
def test_call | |
foo = 1 | |
fooo += 1 | |
end | |
# Run the bad function, triggering a post-mortem debugging session on error: | |
Byebug.byebug_on_error do | |
test_call | |
end | |
# The reason for re-raising the exception is to enable error recovery: | |
begin | |
Byebug.byebug_on_error do | |
test_call | |
end | |
rescue | |
# Log error, continue process | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment