From 3ba1df86703ea60e0b53a67905fc62a52b61e804 Mon Sep 17 00:00:00 2001 From: ยท๐‘‘๐‘ด๐‘•๐‘‘๐‘ฉ๐‘ค Date: Fri, 12 Dec 2025 17:55:05 +0000 Subject: redo some latest_cmd funs --- lib/error.ml | 3 +-- lib/input_foreman.ml | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/error.ml b/lib/error.ml index 83cca60..da5e579 100644 --- a/lib/error.ml +++ b/lib/error.ml @@ -42,8 +42,7 @@ type input_foreman_error = [ | `Could_not_get of Name.t | `Could_not_set of Name.t | `Latest_cmd_empty of Name.t - | `Latest_cmd_fail of Name.t * string - | `Latest_cmd_stderr of Name.t * string + | `Latest_cmd_fail of Name.t * exn * string | `Prefetch of Name.t * prefetch_error | `Pool_exception of string (* FIXME: string list *) diff --git a/lib/input_foreman.ml b/lib/input_foreman.ml index 8963ee0..895a506 100644 --- a/lib/input_foreman.ml +++ b/lib/input_foreman.ml @@ -440,8 +440,8 @@ let run_pipeline ~sw ~proc_mgr ~(models : Input.jg_models2) cmds = let rec build_pipeline ?stdin = function | {prog; args}, [] -> begin - let stdout_buf = Buffer.create 512 - and stderr_buf = Buffer.create 512 + let stdout_buf = Buffer.create 1024 + and stderr_buf = Buffer.create 1024 in let stdout_sink = Eio.Flow.buffer_sink stdout_buf and stderr_sink = Eio.Flow.buffer_sink stderr_buf @@ -451,14 +451,14 @@ let run_pipeline ~sw ~proc_mgr ~(models : Input.jg_models2) cmds = Eio.Process.run proc_mgr ?stdin ~stdout: stdout_sink ~stderr: stderr_sink cmd; Option.iter Eio.Resource.close stdin; (* close pipe input after last process *) - Ok (stdout_buf, stderr_buf) + Ok stdout_buf with - | exn -> Error (Printexc.to_string exn) + | exn -> Error (exn, stderr_buf) end | {prog; args}, next :: rest -> begin let pipe_in, pipe_out = Eio.Process.pipe ~sw proc_mgr in - let stderr_buf = Buffer.create 512 in + let stderr_buf = Buffer.create 1024 in let stderr_sink = Eio.Flow.buffer_sink stderr_buf and cmd = List.map (Input.Template.fill ~models) (prog :: args) in @@ -468,7 +468,7 @@ let run_pipeline ~sw ~proc_mgr ~(models : Input.jg_models2) cmds = (* close writer after child is spawned *) build_pipeline ~stdin: pipe_in (next, rest) with - | exn -> Error (Printexc.to_string exn) + | exn -> Error (exn, stderr_buf) end in build_pipeline cmds @@ -482,18 +482,12 @@ let get_latest ~sw ~proc_mgr input : (string option, error) result = and models = Input.jg_models2 input in match run_pipeline ~sw ~proc_mgr ~models cmds with - | Error err -> Error (`Latest_cmd_fail (name, err)) - | Ok (stdout_buf, stderr_buf) -> - let stderr_str = String.trim @@ Buffer.contents stderr_buf in - (* & shame on you for putting non-errors in the stderr *) - if stderr_str <> "" then - Error (`Latest_cmd_stderr (name, stderr_str)) - else - let latest_str = String.trim @@ Buffer.contents stdout_buf in - if latest_str = "" then - Error (`Latest_cmd_empty name) - else - Ok (Some latest_str) + | Error (exn, stderr) -> + Error (`Latest_cmd_fail (name, exn, String.trim @@ Buffer.contents stderr)) + | Ok stdout_buf -> + match String.trim @@ Buffer.contents stdout_buf with + | "" -> Error (`Latest_cmd_empty name) + | latest_str -> Ok (Some latest_str) type latest_result = [ | `LacksCmd -- cgit v1.2.3