lib/cli/kit/error_handler.rb in cli-kit-3.3.0 vs lib/cli/kit/error_handler.rb in cli-kit-4.0.0
- old
+ new
@@ -20,11 +20,11 @@
install!
handle_abort(&block)
end
def handle_exception(error)
- if notify_with = exception_for_submission(error)
+ if (notify_with = exception_for_submission(error))
logs = begin
File.read(@log_file)
rescue => e
"(#{e.class}: #{e.message})"
end
@@ -44,21 +44,21 @@
when Interrupt # ctrl-c
nil
when CLI::Kit::Abort, CLI::Kit::AbortSilent # Not a bug
nil
when SignalException
- skip = %w(SIGTERM SIGHUP SIGINT)
+ skip = ['SIGTERM', 'SIGHUP', 'SIGINT']
skip.include?(error.message) ? nil : error
when SystemExit # "exit N" called
case error.status
when CLI::Kit::EXIT_SUCCESS # submit nothing if it was `exit 0`
nil
when CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
# if it was `exit 30`, translate the exit code to 1, and submit nothing.
# 30 is used to signal normal failures that are not indicative of bugs.
# However, users should see it presented as 1.
- exit 1
+ exit(1)
else
# A weird termination status happened. `error.exception "message"` will maintain backtrace
# but allow us to set a message
error.exception("abnormal termination status: #{error.status}")
end
@@ -81,19 +81,25 @@
print_error_message(e) unless is_silent
(@exception = e) if is_bug
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
rescue Interrupt
- $stderr.puts(format_error_message("Interrupt"))
+ stderr_puts_message('Interrupt')
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
rescue Errno::ENOSPC
message = if @tool_name
"Your disk is full - {{command:#{@tool_name}}} requires free space to operate"
else
- "Your disk is full - free space is required to operate"
+ 'Your disk is full - free space is required to operate'
end
- $stderr.puts(format_error_message(message))
+ stderr_puts_message(message)
CLI::Kit::EXIT_FAILURE_BUT_NOT_BUG
+ end
+
+ def stderr_puts_message(message)
+ $stderr.puts(format_error_message(message))
+ rescue Errno::EPIPE
+ nil
end
def exception_reporter
if @exception_reporter_or_proc.respond_to?(:report)
@exception_reporter_or_proc