fix: add better handling of exceptions (parsing, arguments, options, ...)
This commit is contained in:
parent
8b0d64ad86
commit
60a7356f8b
2 changed files with 16 additions and 2 deletions
11
src/cli.cr
11
src/cli.cr
|
@ -30,13 +30,22 @@ module GX
|
||||||
Parsers::RootParser.new.build(parser, breadcrumbs, @config)
|
Parsers::RootParser.new.build(parser, breadcrumbs, @config)
|
||||||
end
|
end
|
||||||
pparser.parse(args)
|
pparser.parse(args)
|
||||||
|
rescue e : OptionParser::MissingOption
|
||||||
|
STDERR.puts "ERROR: #{e.message}".colorize(:red)
|
||||||
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
command = CommandFactory.create_command(@config, @config.mode)
|
command = CommandFactory.create_command(@config, @config.mode)
|
||||||
abort("ERROR: unknown command for mode #{@config.mode}") if command.nil?
|
abort("ERROR: unknown command for mode #{@config.mode}") if command.nil?
|
||||||
|
|
||||||
command.try &.execute
|
command.execute
|
||||||
|
rescue e : ArgumentError
|
||||||
|
STDERR.puts "ERROR: #{e.message}".colorize(:red)
|
||||||
|
exit(1)
|
||||||
|
rescue e : Exception
|
||||||
|
STDERR.puts "ERROR: #{e.message}".colorize(:red)
|
||||||
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,7 +102,12 @@ module GX
|
||||||
file_data = File.read(config_path)
|
file_data = File.read(config_path)
|
||||||
file_patched = Crinja.render(file_data, {"env" => ENV.to_h})
|
file_patched = Crinja.render(file_data, {"env" => ENV.to_h})
|
||||||
|
|
||||||
root = Models::RootConfig.from_yaml(file_patched)
|
begin
|
||||||
|
root = Models::RootConfig.from_yaml(file_patched)
|
||||||
|
rescue ex : YAML::ParseException
|
||||||
|
STDERR.puts "Error parsing configuration file: #{ex.message}".colorize(:red)
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
mount_point_base_safe = root.global.mount_point_base
|
mount_point_base_safe = root.global.mount_point_base
|
||||||
raise Models::InvalidMountpointError.new("Invalid global mount point") if mount_point_base_safe.nil?
|
raise Models::InvalidMountpointError.new("Invalid global mount point") if mount_point_base_safe.nil?
|
||||||
|
|
Loading…
Reference in a new issue