lib/nanoc/cli/error_handler.rb in nanoc-4.8.15 vs lib/nanoc/cli/error_handler.rb in nanoc-4.8.16

- old
+ new

@@ -3,27 +3,18 @@ module Nanoc::CLI # Catches errors and prints nice diagnostic messages, then exits. # # @api private class ErrorHandler - # @param [Nanoc::CLI::Command, nil] command The command that is - # currently being executed, or nil if there is none - def initialize(command: nil) - @command = command - end - # Enables error handling in the given block. # - # @param [Nanoc::CLI::Command, nil] command The command that is - # currently being executed, or nil if there is none - # # @return [void] - def self.handle_while(command: nil, &block) + def self.handle_while(exit_on_error: true) if @disabled yield else - new(command: command).handle_while(&block) + new.handle_while(exit_on_error: exit_on_error) { yield } end end # Disables error handling. This is used by the test cases to prevent error # from being handled by the CLI while tests are running. @@ -40,11 +31,11 @@ # Enables error handling in the given block. This method should not be # called directly; use {Nanoc::CLI::ErrorHandler.handle_while} instead. # # @return [void] - def handle_while(&_block) + def handle_while(exit_on_error:) # Set exit handler %w[INT TERM].each do |signal| Signal.trap(signal) do puts exit!(0) @@ -72,11 +63,11 @@ resolution = resolution_for(e) $stderr.puts resolution if resolution else print_error(e) end - exit(1) + exit(1) if exit_on_error end # Prints the given error to stderr. Includes message, possible resolution # (see {#resolution_for}), compilation stack, backtrace, etc. # @@ -188,9 +179,10 @@ 'less' => 'less', 'listen' => 'listen', 'markaby' => 'markaby', 'maruku' => 'maruku', 'mime/types' => 'mime-types', + 'nanoc/live' => 'nanoc-live', 'nokogiri' => 'nokogiri', 'nokogumbo' => 'nokogumbo', 'pry' => 'pry', 'rack' => 'rack', 'rack/cache' => 'rack-cache',