Stack trace on early Ctrl-C
rfdonnelly opened this issue · comments
If SIGINT (Ctrl-C) is sent immediately after invoking jobrnr, a stacktrace is printed. Adding rescue Interrupt
in Jobrnr::Application::run
will handle any SIGINTs received before getting to Jobrnr::Job::Dispatch::trap_ctrl_c
but it will still miss any SIGINTs received before then. Is it possible to capture all SIGINTS?
Error
> jobrnr
^CTraceback (most recent call last):
12: from <internal:gem_prelude>:1:in `<internal:gem_prelude>'
11: from <internal:gem_prelude>:1:in `require'
10: from .../ruby/2.7.2/lib/ruby/2.7.0/rubygems.rb:1438:in `<top (required)>'
9: from .../ruby/2.7.2/lib/ruby/2.7.0/rubygems/specification.rb:867:in `load_defaults'
...
1: from .../ruby/2.7.2/lib/ruby/2.7.0/rubygems/specification.rb:1114:in `load'
.../ruby/2.7.2/lib/ruby/2.7.0/rubygems/specification.rb:1114:in `file?': Interrupt
Possible Solution
Wrap the entire application in a begin/rescue block.
diff --git a/bin/jobrnr b/bin/jobrnr
index 73e823b..a48013c 100755
--- a/bin/jobrnr
+++ b/bin/jobrnr
@@ -1,6 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-require_relative "../lib/jobrnr"
+begin
+ require_relative "../lib/jobrnr"
-exit Jobrnr::Application.new(ARGV).run
+ exit Jobrnr::Application.new(ARGV).run
+rescue Interrupt
+ Jobrnr::Log.error "Received SIGINT"
+ exit 130
+end