Skip to content

Commit f06ef64

Browse files
committed
fixup! os: Add exception_on_failure to os:cmd/2
1 parent 6ef49d8 commit f06ef64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/kernel/src/os.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@ The possible options are:
557557
_Example_:
558558

559559
```erlang
560-
> catch os:cmd("true && false", #{ exception_on_failure => true }).
560+
> catch os:cmd("echo hello && exit 123", #{ exception_on_failure => true }).
561+
{'EXIT',{{command_failed,"hello\n",123},
562+
[{os,cmd,2,[{file,"os.erl"},{line,579}]},
561563
...
562564
```
563565

@@ -573,6 +575,8 @@ cmd(Cmd, Opts) ->
573575
try
574576
do_cmd(Cmd, Opts)
575577
catch
578+
throw:{command_failed, Result, ExitStatus} ->
579+
error({command_failed, Result, ExitStatus});
576580
throw:badopt ->
577581
badarg_with_cause([Cmd, Opts], badopt);
578582
throw:{open_port, Reason} ->
@@ -601,7 +605,7 @@ do_cmd(Cmd, Opts) ->
601605
true -> binary_to_list(iolist_to_binary(Bytes))
602606
end,
603607
if ExceptionOnFailure, ExitStatus =/= 0 ->
604-
error({command_failed, Result, ExitStatus});
608+
throw({command_failed, Result, ExitStatus});
605609
true -> Result
606610
end.
607611

0 commit comments

Comments
 (0)