From 459e287ff11551c26d8ba79c63e6586e9c3f2487 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Tue, 3 Mar 2020 12:55:41 +0100 Subject: [PATCH] B #2689: add error handling (#4294) --- src/cli/command_parser.rb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index 006ee8d9f6..c7de7113dc 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -453,7 +453,7 @@ module CommandParser if comm.nil? print_help - exit -1 + exit 0 end if comm[:deprecated] @@ -464,16 +464,27 @@ module CommandParser parse(extra_options) if comm - @before_proc.call if @before_proc + begin + @before_proc.call if @before_proc + rescue StandardError => e + STDERR.puts e.message + exit(-1) + end check_args!(comm_name, comm[:arity], comm[:args_format]) - rc = comm[:proc].call - if rc.instance_of?(Array) - puts rc[1] - exit rc.first - else - exit(@exit_code || rc) + begin + rc = comm[:proc].call + + if rc.instance_of?(Array) + puts rc[1] + exit rc.first + else + exit(@exit_code || rc) + end + rescue StandardError => e + STDERR.puts e.message + exit(-1) end end end @@ -501,10 +512,10 @@ module CommandParser with_proc<