Skip to content

Commit

Permalink
fixup! os: Add exception_on_failure to os:cmd/2
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Dec 10, 2024
1 parent 6ef49d8 commit f06ef64
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/kernel/src/os.erl
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ The possible options are:
_Example_:
```erlang
> catch os:cmd("true && false", #{ exception_on_failure => true }).
> catch os:cmd("echo hello && exit 123", #{ exception_on_failure => true }).
{'EXIT',{{command_failed,"hello\n",123},
[{os,cmd,2,[{file,"os.erl"},{line,579}]},
...
```
Expand All @@ -573,6 +575,8 @@ cmd(Cmd, Opts) ->
try
do_cmd(Cmd, Opts)
catch
throw:{command_failed, Result, ExitStatus} ->
error({command_failed, Result, ExitStatus});
throw:badopt ->
badarg_with_cause([Cmd, Opts], badopt);
throw:{open_port, Reason} ->
Expand Down Expand Up @@ -601,7 +605,7 @@ do_cmd(Cmd, Opts) ->
true -> binary_to_list(iolist_to_binary(Bytes))
end,
if ExceptionOnFailure, ExitStatus =/= 0 ->
error({command_failed, Result, ExitStatus});
throw({command_failed, Result, ExitStatus});
true -> Result
end.

Expand Down

0 comments on commit f06ef64

Please sign in to comment.