mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
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:
parent
c78a6b62c9
commit
589833bca7
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 *)
|
||||
|
@ -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
|
||||
@
|
||||
|
Loading…
Reference in New Issue
Block a user