[log] append ERROR in front of `failwith` toplevel messages

Summary:
This makes it clearer that something went wrong. Most `failwith` did not set
this prefix already, so I opted to append it automatically and remove it from
the few instances that added it manually.

Also add quotes around bad user arguments to lessen possible confusion.

Reviewed By: jberdine

Differential Revision: D5182272

fbshipit-source-id: 20e4769
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent b50f9f2695
commit 03bd3f1df1

@ -663,15 +663,15 @@ let anon_fun arg =
command_switch ()
| Some command ->
raise (Arg.Bad
("More than one subcommand specified: " ^ string_of_command command ^ ", " ^
arg))
(Printf.sprintf "More than one subcommand specified: '%s', '%s'"
(string_of_command command) arg))
else match !anon_arg_action.on_unknown with
| `Add ->
rev_anon_args := arg::!rev_anon_args
| `Skip ->
()
| `Reject ->
raise (Arg.Bad ("unexpected anonymous argument: " ^ arg))
raise (Arg.Bad (Printf.sprintf "Unexpected anonymous argument: '%s'" arg))
let decode_inferconfig_to_argv path =

@ -1653,7 +1653,7 @@ let post_parsing_initialization command_opt =
Caml.Printexc.set_uncaught_exception_handler
(fun exn _ ->
let exn_msg = match exn with
| Failure msg -> msg
| Failure msg -> "ERROR: " ^ msg
| _ -> "ERROR: " ^ Caml.Printexc.to_string exn in
Format.eprintf "%s@?" exn_msg
);

@ -243,7 +243,7 @@ let shell_escape_command cmd =
let create_dir dir =
try
if (Unix.stat dir).Unix.st_kind <> Unix.S_DIR then
failwithf "@.ERROR: file %s exists and is not a directory@." dir
failwithf "file %s exists and is not a directory@." dir
with Unix.Unix_error _ ->
try Unix.mkdir dir ~perm:0o700 with
Unix.Unix_error _ ->
@ -251,7 +251,7 @@ let create_dir dir =
try Polymorphic_compare.(=) ((Unix.stat dir).Unix.st_kind) Unix.S_DIR
with Unix.Unix_error _ -> false in
if not created_concurrently then
failwithf "@.ERROR: cannot create directory %s@." dir
failwithf "cannot create directory %s@." dir
let realpath_cache = Hashtbl.create 1023

@ -1280,7 +1280,7 @@ let quotient_access_map acc_map =
let (k_part, non_k_part) =
AccessListMap.partition (fun k' _ -> may_alias tenv k k') m in
if AccessListMap.is_empty k_part
then failwith "Error: may_alias is not reflexive!";
then failwith "may_alias is not reflexive!";
let k_accesses =
AccessListMap.fold
(fun _ v acc' -> List.append v acc')

@ -31,7 +31,7 @@ let visit_ast
| None ->
()
| Some error ->
failwithf "ERROR: visiting the clang AST failed with error %s"
failwithf "visiting the clang AST failed with error %s"
(Ag_util.Validation.string_of_error error)
let get_ptr_from_node node =

@ -33,7 +33,7 @@ let already_imported_files = ref []
let rec parse_import_file import_file channel : CTL.clause list =
if List.mem !already_imported_files import_file then
failwith ("[ERROR] Cyclic imports: file '" ^ import_file ^ "' was already imported.")
failwith ("Cyclic imports: file '" ^ import_file ^ "' was already imported.")
else (
match parse_al_file import_file channel with
| Some {import_files = imports; global_macros = curr_file_macros; checkers = _} ->

@ -23,9 +23,9 @@ let filter_parsed_linters_developer parsed_linters =
if List.length parsed_linters > 1 && Config.linters_developer_mode then
match Config.linter with
| None ->
failwith ("ERROR: In linters developer mode you should debug only one linter at a time. \
This is important for debugging the rule. Pass the flag \
--linter <name> to specify the linter you want to debug.");
failwith "In linters developer mode you should debug only one linter at a time. \
This is important for debugging the rule. Pass the flag \
--linter <name> to specify the linter you want to debug.";
| Some lint ->
List.filter ~f:(
fun (rule : linter) -> String.equal rule.issue_desc.name lint
@ -250,7 +250,7 @@ let expand_formula phi _map _error_msg =
let f1_sub = apply_substitution f1 sub in
let map' = ALVar.FormulaIdMap.add av (true, fparams, f1) map in
expand f1_sub map' error_msg'
| None -> failwith ("[ERROR]: Formula identifier '" ^ name ^
| None -> failwith ("Formula identifier '" ^ name ^
"' is not called with the right number of parameters"))
with Not_found -> acc)) (* in this case it should be a predicate *)
| Not f1 -> Not (expand f1 map error_msg)
@ -275,7 +275,7 @@ let _build_macros_map macros init_map =
let macros_map = List.fold ~f:(fun map' data -> match data with
| CTL.CLet (key, params, formula) ->
if ALVar.FormulaIdMap.mem key map' then
failwith ("[ERROR] Macro '" ^ (ALVar.formula_id_to_string key) ^
failwith ("Macro '" ^ (ALVar.formula_id_to_string key) ^
"' has more than one definition.")
else ALVar.FormulaIdMap.add key (false, params, formula) map'
| _ -> map') ~init:init_map macros in

@ -140,8 +140,8 @@ clause:
{ Logging.out "\tParsed SET clause\n";
let alvar = match $2 with
| "report_when" -> ALVar.Report_when
| _ -> failwith ("[ERROR] string '%s' cannot be set to a variable. " ^
"Use the reserverd variable 'report_when'\n") in
| _ -> failwith "string '%s' cannot be set to a variable. \
Use the reserverd variable 'report_when'" in
CTL.CSet (alvar, $4) }
| SET identifier ASSIGNMENT STRING
{ Logging.out "\tParsed SET clause\n";
@ -151,7 +151,7 @@ clause:
| "severity" -> ALVar.Severity
| "mode" -> ALVar.Mode
| "path" -> ALVar.Path
| _ -> failwithf "[ERROR] string '%s' cannot be set in a SET clause. \
| _ -> failwithf "string '%s' cannot be set in a SET clause. \
Use either of: \
'message', 'mode', 'severity', 'suggestion' or 'path'" $2 in
CTL.CDesc (alvar, $4) }

@ -17,7 +17,7 @@ let target_of_string target =
let flavors = String.split flavors_string ~on:',' in
{name; flavors}
| name::[] -> { name; flavors=[] }
| _ -> failwithf "Error: cannot parse target %s" target
| _ -> failwithf "cannot parse target %s" target
let string_of_target { name; flavors } =
let pp_string fmt s = Format.fprintf fmt "%s" s in

@ -94,7 +94,7 @@ let get_compilation_database_files_buck ~prog ~args =
Utils.with_process_in buck_targets_shell In_channel.input_lines in
match exit_or_signal with
| Error _ as status ->
failwithf "*** ERROR: command failed:@\n*** %s@\n*** %s@."
failwithf "*** command failed:@\n*** %s@\n*** %s@."
buck_targets_shell
(Unix.Exit_or_signal.to_string_hum status)
| Ok () ->

@ -45,6 +45,6 @@ let capture compiler ~prog ~args =
|> function
| Ok () -> ()
| Error _ as status ->
failwithf "*** ERROR: capture command failed:@\n*** %s@\n*** %s@."
failwithf "*** capture command failed:@\n*** %s@\n*** %s@."
(String.concat ~sep:" " (prog::args))
(Unix.Exit_or_signal.to_string_hum status)

@ -63,7 +63,7 @@ let compile compiler build_prog build_args =
k ()
| None, (`UnixError (err, log)) ->
let verbose_errlog = Utils.with_file_in verbose_out_file ~f:In_channel.input_all in
failwithf "@\n*** ERROR Failed to execute compilation command: %s@\n*** Command: %s@\n\
failwithf "@\n*** Failed to execute compilation command: %s@\n*** Command: %s@\n\
*** Output:@\n%s%s@\n*** Infer needs a working compilation command to run.@."
(Unix.Exit_or_signal.to_string_hum (Error err)) shell_cmd log verbose_errlog;
| None, (`ExceptionError exn) ->

@ -157,6 +157,6 @@ let capture ~prog ~args =
|> function
| Ok () -> ()
| Error _ as status ->
failwithf "*** ERROR: Maven command failed:@\n*** %s@\n*** %s@\n"
failwithf "*** Maven command failed:@\n*** %s@\n*** %s@\n"
(String.concat ~sep:" " (prog::capture_args))
(Unix.Exit_or_signal.to_string_hum status)

Loading…
Cancel
Save