Make plugin load failures less verbose

In general you don't care unless you may have attempted to use one.
This commit is contained in:
Louis Gesbert 2024-02-21 12:06:38 +01:00
parent c78a6b62c9
commit 589833bca7
4 changed files with 18 additions and 1 deletions

View File

@ -1102,7 +1102,9 @@ let main () =
let open Cmdliner in
match Cmd.eval_value ~catch:false ~argv command with
| Ok _ -> exit Cmd.Exit.ok
| Error _ -> exit Cmd.Exit.cli_error
| Error e ->
if e = `Term then Plugin.print_failures ();
exit Cmd.Exit.cli_error
| exception Cli.Exit_with n -> exit n
| exception Message.CompilerError content ->
let bt = Printexc.get_raw_backtrace () in

View File

@ -29,6 +29,13 @@ let register info term =
let list () = Hashtbl.to_seq_values backend_plugins |> List.of_seq
let names () = Hashtbl.to_seq_keys backend_plugins |> List.of_seq
let load_failures = Hashtbl.create 17
let print_failures () =
if Hashtbl.length load_failures > 0 then
Message.emit_warning "Some plugins could not be loaded:@,%a"
(Format.pp_print_seq (fun ppf -> Format.fprintf ppf " - %s")) (Hashtbl.to_seq_values load_failures)
let load_file f =
try
Dynlink.loadfile f;
@ -36,6 +43,10 @@ let load_file f =
with
| Dynlink.Error (Dynlink.Module_already_loaded s) ->
Message.emit_debug "Plugin %S (%s) was already loaded, skipping" f s
| Dynlink.Error err ->
let msg = Dynlink.error_message err in
Message.emit_debug "Could not load plugin %S: %s" f msg;
Hashtbl.add load_failures f msg
| e ->
Message.emit_warning "Could not load plugin %S: %s" f (Printexc.to_string e)

View File

@ -41,3 +41,6 @@ val load_file : string -> unit
val load_dir : string -> unit
(** Load all plugins found in the given directory *)
val print_failures : unit -> unit
(** Dynlink errors may be silenced at startup time if not in --debug mode, this prints them as warnings *)

View File

@ -543,6 +543,7 @@ and translate_statements (ctxt : 'm ctxt) (block_expr : 'm L.expr) : A.block =
Expr.pos block_expr );
]
| _ -> (
Message.emit_debug "E: %a" Expr.format block_expr;
let e_stmts, new_e = translate_expr ctxt block_expr in
e_stmts
@