@@ -9,9 +9,10 @@ module [
99 exec_output!,
1010 exec!,
1111 exec_cmd!,
12+ exec_exit_code!,
1213]
1314
14- import InternalCmd
15+ import InternalCmd exposing [to_str]
1516import InternalIOErr exposing [IOErr ]
1617import Host
1718
@@ -22,9 +23,9 @@ Cmd := InternalCmd.Command
2223## If you want to capture the output, use [exec_output!].
2324## ```
2425## # Call echo to print "hello world"
25- ## Cmd.exec!("echo", ["hello world"]) ? |err| CmdEchoFailed(err)
26+ ## Cmd.exec!("echo", ["hello world"])?
2627## ```
27- exec ! : Str , List Str => Result {} [ExecFailed Str ( List Str ) I32 , FailedToGetExitCode IOErr ]
28+ exec ! : Str , List Str => Result {} [ExecFailed Str I32 , FailedToGetExitCode Str IOErr ]
2829exec ! = |cmd_name, arguments|
2930 exit_code =
3031 new(cmd_name)
@@ -34,7 +35,8 @@ exec! = |cmd_name, arguments|
3435 if exit_code == 0i32 then
3536 Ok ({})
3637 else
37- Err (ExecFailed (cmd_name, arguments, exit_code))
38+ cmd_str = " ${cmd_name} ${Str.join_with(arguments, " " )}"
39+ Err (ExecFailed (cmd_str, exit_code))
3840
3941## Execute a Cmd while inheriting stdin, stdout and stderr from parent.
4042## You should prefer using `exec!`, only use this if you want to use [env], [envs] or [clear_envs].
@@ -46,15 +48,15 @@ exec! = |cmd_name, arguments|
4648## |> Cmd.env("RUST_BACKTRACE", "1")
4749## |> Cmd.exec_cmd!()?
4850## ```
49- exec_cmd ! : Cmd => Result {} [ExecCmdFailed Cmd I32 , FailedToGetExitCode IOErr ]
50- exec_cmd ! = |cmd|
51+ exec_cmd ! : Cmd => Result {} [ExecCmdFailed Str I32 , FailedToGetExitCode Str IOErr ]
52+ exec_cmd ! = |@ Cmd ( cmd) |
5153 exit_code =
52- exec_exit_code!(cmd)?
54+ exec_exit_code!(@ Cmd ( cmd) )?
5355
5456 if exit_code == 0i32 then
5557 Ok ({})
5658 else
57- Err (ExecCmdFailed (cmd, exit_code))
59+ Err (ExecCmdFailed (to_str( cmd) , exit_code))
5860
5961## Execute command and capture stdout, stderr and the exit code in [Output].
6062##
@@ -66,16 +68,16 @@ exec_output! : Cmd =>
6668 Result
6769 {stdout_utf8 : Str , stderr_utf8_lossy : Str }
6870 [
69- StdoutContainsInvalidUtf8 ([BadUtf8 { index : U64 , problem : Str . Utf8Problem }]),
70- NonZeroExitCode ({exit_code: I32 , stdout_utf8_lossy: Str , stderr_utf8_lossy: Str }),
71- FailedToGetExitCode (IOErr )
71+ StdoutContainsInvalidUtf8 ({ cmd : Str , err: [BadUtf8 { index : U64 , problem : Str . Utf8Problem }]} ),
72+ NonZeroExitCode ({cmd : Str , exit_code: I32 , stdout_utf8_lossy: Str , stderr_utf8_lossy: Str }),
73+ FailedToGetExitCode ({ cmd : Str , err : IOErr } )
7274 ]
7375exec_output ! = |@Cmd (cmd)|
7476 exec_res = Host . command_exec_output !(cmd )
7577
7678 when exec_res is
7779 Ok ({stdout_bytes, stderr_bytes}) ->
78- stdout_utf8 = Str . from_utf8 (stdout_bytes ) ? |err| StdoutContainsInvalidUtf8 (err)
80+ stdout_utf8 = Str . from_utf8 (stdout_bytes ) ? |err| StdoutContainsInvalidUtf8 ({ cmd: to_str(cmd), err} )
7981 stderr_utf8_lossy = Str . from_utf8_lossy (stderr_bytes )
8082
8183 Ok ({stdout_utf8, stderr_utf8_lossy})
@@ -85,20 +87,20 @@ exec_output! = |@Cmd(cmd)|
8587 stdout_utf8_lossy = Str . from_utf8_lossy (stdout_bytes )
8688 stderr_utf8_lossy = Str . from_utf8_lossy (stderr_bytes )
8789
88- Err (NonZeroExitCode ({exit_code, stdout_utf8_lossy, stderr_utf8_lossy}))
90+ Err (NonZeroExitCode ({cmd : to_str(cmd), exit_code, stdout_utf8_lossy, stderr_utf8_lossy}))
8991 Err (err) ->
9092 Err (InternalIOErr . handle_err (err ))
91- |> Result . map_err (FailedToGetExitCode )
93+ |> Result . map_err (| er | FailedToGetExitCode ({ cmd : to_str(cmd), err : er }) )
9294
9395# TODO exec_output_bytes
9496
9597## Execute command and inherit stdin, stdout and stderr from parent. Returns the exit code.
9698## Helper function.
97- exec_exit_code ! : Cmd => Result I32 [FailedToGetExitCode IOErr ]
99+ exec_exit_code ! : Cmd => Result I32 [FailedToGetExitCode Str IOErr ]
98100exec_exit_code ! = |@Cmd (cmd)|
99101 Host . command_exec_exit_code !(cmd )
100102 |> Result . map_err (InternalIOErr . handle_err )
101- |> Result . map_err (FailedToGetExitCode )
103+ |> Result . map_err (| err | FailedToGetExitCode (to_str(cmd), err) )
102104
103105# This hits a compiler bug: Alias `6.IdentId(11)` not registered in delayed aliases! ...
104106# ## Converts output into a utf8 string. Invalid utf8 sequences in stderr are ignored.
0 commit comments