From be254f49efc7e3e75b1bda644707231a0ed96bca Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Thu, 13 Feb 2025 16:50:22 +0000 Subject: [PATCH] Don't backtrace on invalid input in compile-deps Closes #983 --- src/odoc/bin/main.ml | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/odoc/bin/main.ml b/src/odoc/bin/main.ml index 8dd97168a2..a7c8704730 100644 --- a/src/odoc/bin/main.ml +++ b/src/odoc/bin/main.ml @@ -1410,15 +1410,29 @@ end) module Depends = struct module Compile = struct let list_dependencies input_files = - let deps = - Depends.for_compile_step (List.map ~f:Fs.File.of_string input_files) - in - List.iter - ~f:(fun t -> - Printf.printf "%s %s\n" (Depends.Compile.name t) - (Digest.to_hex @@ Depends.Compile.digest t)) - deps; - flush stdout + try + let deps = + Depends.for_compile_step (List.map ~f:Fs.File.of_string input_files) + in + List.iter + ~f:(fun t -> + Printf.printf "%s %s\n" (Depends.Compile.name t) + (Digest.to_hex @@ Depends.Compile.digest t)) + deps; + flush stdout + with Cmi_format.Error e -> + let msg = + match e with + | Not_an_interface file -> + Printf.sprintf "File %S is not an interface" file + | Wrong_version_interface (file, v) -> + Printf.sprintf "File %S is compiled for %s version of OCaml" file + v + | Corrupted_interface file -> + Printf.sprintf "File %S is corrupted" file + in + Printf.eprintf "ERROR: %s\n%!" msg; + exit 1 let cmd = let input =