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

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

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

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

@ -31,7 +31,7 @@ let visit_ast
| None -> | None ->
() ()
| Some error -> | 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) (Ag_util.Validation.string_of_error error)
let get_ptr_from_node node = 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 = let rec parse_import_file import_file channel : CTL.clause list =
if List.mem !already_imported_files import_file then 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 ( else (
match parse_al_file import_file channel with match parse_al_file import_file channel with
| Some {import_files = imports; global_macros = curr_file_macros; checkers = _} -> | 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 if List.length parsed_linters > 1 && Config.linters_developer_mode then
match Config.linter with match Config.linter with
| None -> | None ->
failwith ("ERROR: In linters developer mode you should debug only one linter at a time. \ failwith "In linters developer mode you should debug only one linter at a time. \
This is important for debugging the rule. Pass the flag \ This is important for debugging the rule. Pass the flag \
--linter <name> to specify the linter you want to debug."); --linter <name> to specify the linter you want to debug.";
| Some lint -> | Some lint ->
List.filter ~f:( List.filter ~f:(
fun (rule : linter) -> String.equal rule.issue_desc.name lint 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 f1_sub = apply_substitution f1 sub in
let map' = ALVar.FormulaIdMap.add av (true, fparams, f1) map in let map' = ALVar.FormulaIdMap.add av (true, fparams, f1) map in
expand f1_sub map' error_msg' 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")) "' is not called with the right number of parameters"))
with Not_found -> acc)) (* in this case it should be a predicate *) with Not_found -> acc)) (* in this case it should be a predicate *)
| Not f1 -> Not (expand f1 map error_msg) | 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 let macros_map = List.fold ~f:(fun map' data -> match data with
| CTL.CLet (key, params, formula) -> | CTL.CLet (key, params, formula) ->
if ALVar.FormulaIdMap.mem key map' then 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.") "' has more than one definition.")
else ALVar.FormulaIdMap.add key (false, params, formula) map' else ALVar.FormulaIdMap.add key (false, params, formula) map'
| _ -> map') ~init:init_map macros in | _ -> map') ~init:init_map macros in

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

@ -17,7 +17,7 @@ let target_of_string target =
let flavors = String.split flavors_string ~on:',' in let flavors = String.split flavors_string ~on:',' in
{name; flavors} {name; flavors}
| name::[] -> { 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 string_of_target { name; flavors } =
let pp_string fmt s = Format.fprintf fmt "%s" s in 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 Utils.with_process_in buck_targets_shell In_channel.input_lines in
match exit_or_signal with match exit_or_signal with
| Error _ as status -> | Error _ as status ->
failwithf "*** ERROR: command failed:@\n*** %s@\n*** %s@." failwithf "*** command failed:@\n*** %s@\n*** %s@."
buck_targets_shell buck_targets_shell
(Unix.Exit_or_signal.to_string_hum status) (Unix.Exit_or_signal.to_string_hum status)
| Ok () -> | Ok () ->

@ -45,6 +45,6 @@ let capture compiler ~prog ~args =
|> function |> function
| Ok () -> () | Ok () -> ()
| Error _ as status -> | 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)) (String.concat ~sep:" " (prog::args))
(Unix.Exit_or_signal.to_string_hum status) (Unix.Exit_or_signal.to_string_hum status)

@ -63,7 +63,7 @@ let compile compiler build_prog build_args =
k () k ()
| None, (`UnixError (err, log)) -> | None, (`UnixError (err, log)) ->
let verbose_errlog = Utils.with_file_in verbose_out_file ~f:In_channel.input_all in 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.@." *** 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; (Unix.Exit_or_signal.to_string_hum (Error err)) shell_cmd log verbose_errlog;
| None, (`ExceptionError exn) -> | None, (`ExceptionError exn) ->

@ -157,6 +157,6 @@ let capture ~prog ~args =
|> function |> function
| Ok () -> () | Ok () -> ()
| Error _ as status -> | 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)) (String.concat ~sep:" " (prog::capture_args))
(Unix.Exit_or_signal.to_string_hum status) (Unix.Exit_or_signal.to_string_hum status)

Loading…
Cancel
Save