From 32b11be9cf37d4e92348dce0a084eaefe8e8cc41 Mon Sep 17 00:00:00 2001 From: Qexat <43090614+qexat@users.noreply.github.com> Date: Sat, 22 Feb 2025 11:09:33 +0100 Subject: [PATCH] Provide a better error message in case of failure while cloning the repository --- lib/shell/shell.ml | 12 ++++++++++-- lib/shell/shell.mli | 2 +- lib/tui/init/init.ml | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/shell/shell.ml b/lib/shell/shell.ml index a5e4965..df812ef 100644 --- a/lib/shell/shell.ml +++ b/lib/shell/shell.ml @@ -1,7 +1,15 @@ let proc cmd = Printf.eprintf "🐚 %s\n%!" cmd; - let _exit_code = Unix.system cmd in - () + match Unix.system cmd with + | Unix.WEXITED 0 -> Ok () + | Unix.WEXITED return_code -> + Error + (Printf.sprintf "command '%s' failed with code %d" (String.escaped cmd) + return_code) + | Unix.WSIGNALED number | Unix.WSTOPPED number -> + Error + (Printf.sprintf "command '%s' was stopped by signal (%d)" + (String.escaped cmd) number) let collect_chan (channel : in_channel) : string = let rec loop acc = diff --git a/lib/shell/shell.mli b/lib/shell/shell.mli index dfdecd0..bf1714b 100644 --- a/lib/shell/shell.mli +++ b/lib/shell/shell.mli @@ -3,7 +3,7 @@ Redirect the called process stdout and stderr to the current process stdout. Also print the command with a pretty prompt. *) -val proc : string -> unit +val proc : string -> (unit, string) result (** Run the given CLI command as external process and collect its stdout to the resulting string. *) diff --git a/lib/tui/init/init.ml b/lib/tui/init/init.ml index 80f942a..4245592 100644 --- a/lib/tui/init/init.ml +++ b/lib/tui/init/init.ml @@ -22,7 +22,11 @@ let clone_repo ~owner_repo ~local_path = Printf.sprintf "git clone git@github.com:%s/%s.git %s" owner repo temp_dir in - Shell.proc cmd; + Shell.proc cmd + |> Result.iter_error (fun message -> + Printf.eprintf "❌ %s\n" message; + exit 1); + temp_dir let read_root_tree ~root_dir_path =