Skip to content

Commit b833b59

Browse files
committed
fix(executor): wrap exit program rescue for command & option error
1 parent 8863ad1 commit b833b59

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/cling/executor.cr

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,28 @@ module Cling::Executor
4141
def self.handle(command : Command, results : Array(Parser::Result)) : Int32
4242
resolved_command = resolve_command command, results
4343
unless resolved_command
44-
# TODO: should this be an ExecutionError?
45-
command.on_error CommandError.new("Command '#{results.first.value}' not found")
46-
return 1
44+
begin
45+
# TODO: should this be an ExecutionError?
46+
command.on_error CommandError.new("Command '#{results.first.value}' not found")
47+
return 1
48+
rescue ex : ExitProgram
49+
return ex.code
50+
rescue ex
51+
raise ExecutionError.new "Error while executing command error handler:\n#{ex.message}", cause: ex
52+
end
4753
end
4854

4955
begin
5056
executed = get_in_position resolved_command, results
5157
rescue ex : ExecutionError
52-
resolved_command.on_invalid_option ex.to_s
53-
return 1
58+
begin
59+
resolved_command.on_invalid_option ex.to_s
60+
return 1
61+
rescue ex : ExitProgram
62+
return ex.code
63+
rescue ex
64+
raise ExecutionError.new "Error while executing command error handler:\n#{ex.message}", cause: ex
65+
end
5466
end
5567

5668
begin

0 commit comments

Comments
 (0)