struct
type 'a execution = 'a constraint 'a =
[> `Unix_exec of string
| `Execution of
<host : string; stdout: string option; stderr: string option; message: string>
| `System of [> `Sleep of float ] * [> `Exn of exn ]
| `Timeout of float
| `Ssh_failure of
[> `Wrong_log of string
| `Wrong_status of Ketrew_unix_process.Exit_code.t ] * string ]
type 'a non_zero_execution = 'a constraint 'a =
[> `Non_zero of (string * int) ] execution
let classify (e : _ non_zero_execution) =
match e with
| `System _ | `Timeout _
| `Unix_exec _ -> `Unix
| `Execution _ | `Non_zero _ -> `Execution
| `Ssh_failure _ -> `Ssh
let log e =
let kv k v = Log.(brakets (s k % s " → " % v)) in
match e with
| `Unix_exec failure -> Log.(s "Unix-exec-error: " % s failure)
| `Non_zero (cmd, ex) -> Log.(s "Cmd " % sf "%S" cmd % s " returned " % i ex)
| `System (`Sleep time, `Exn e) ->
Log.(s "System error: sleep " % f time % s " failed: " % exn e)
| `Timeout t -> Log.(s "Timed-out " % parens (f t % s " sec"))
| `Execution exec ->
Log.(
s "Process execution failed: "
% kv "Host" (s exec#host)
% kv "Message" (s exec#message)
% kv "Stdout" (option s exec#stdout)
% kv "Stderr" (option s exec#stderr))
| `Ssh_failure (`Wrong_log log, msg) ->
Log.(s "SSH failed parsing log:" % s msg % kv "Log" (sf "%S" log))
| `Ssh_failure (`Wrong_status exit_code, msg) ->
Log.(s "SSH failed:" % s msg
% kv "Exit code" (Ketrew_unix_process.Exit_code.to_log exit_code))
end