From f06ef6497802d6b1bb28a6a6d1acc745eb5b9f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Backstr=C3=B6m?= Date: Tue, 10 Dec 2024 16:38:53 +0100 Subject: [PATCH] fixup! os: Add exception_on_failure to os:cmd/2 --- lib/kernel/src/os.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl index b1cb27a1b34d..6a1e2ad58b1c 100644 --- a/lib/kernel/src/os.erl +++ b/lib/kernel/src/os.erl @@ -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}]}, ... ``` @@ -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} -> @@ -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.