lib/goodcheck/commands/config_loading.rb in goodcheck-2.7.0 vs lib/goodcheck/commands/config_loading.rb in goodcheck-3.0.0
- old
+ new
@@ -1,8 +1,10 @@
module Goodcheck
module Commands
module ConfigLoading
+ include ExitStatus
+
class ConfigFileNotFound < Error
attr_reader :path
def initialize(path:)
super(path.to_s)
@@ -29,23 +31,26 @@
def handle_config_errors(stderr)
begin
yield
rescue ConfigFileNotFound => exn
stderr.puts "Configuration file not found: #{exn.path}"
- 1
+ EXIT_ERROR
+ rescue ConfigLoader::InvalidPattern => exn
+ stderr.puts exn.message
+ EXIT_ERROR
rescue Psych::Exception => exn
stderr.puts "Unexpected error happens while loading YAML file: #{exn.inspect}"
exn.backtrace.each do |trace_loc|
stderr.puts " #{trace_loc}"
end
- 1
+ EXIT_ERROR
rescue StrongJSON::Type::TypeError, StrongJSON::Type::UnexpectedAttributeError => exn
stderr.puts "Invalid config: #{exn.message}"
stderr.puts StrongJSON::ErrorReporter.new(path: exn.path).to_s
- 1
+ EXIT_ERROR
rescue Errno::ENOENT => exn
stderr.puts "#{exn}"
- 1
+ EXIT_ERROR
end
end
end
end
end