Summary: - failwith police: no more `failwith`. Instead, use `Logging.die`. - Introduce the `SimpleLogging` module for dying from modules where `Logging` cannot be used (usually because that would create a cyclic dependency). - always log backtraces, and show backtraces on the console except for usage errors - Also point out in the log file where the toplevel executions of infer happen Reviewed By: jeremydubreil Differential Revision: D5726362 fbshipit-source-id: d7a01fcmaster
parent
3e660b05ee
commit
1c375a17ac
@ -0,0 +1,41 @@
|
||||
(*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
open! IStd
|
||||
module F = Format
|
||||
|
||||
type error = ExternalError | InternalError | UserError
|
||||
|
||||
exception InferExternalError of string * string
|
||||
|
||||
exception InferInternalError of string * string
|
||||
|
||||
exception InferUserError of string * string
|
||||
|
||||
let raise_error error msg backtrace =
|
||||
match error with
|
||||
| ExternalError
|
||||
-> raise (InferExternalError (msg, backtrace))
|
||||
| InternalError
|
||||
-> raise (InferInternalError (msg, backtrace))
|
||||
| UserError
|
||||
-> raise (InferUserError (msg, backtrace))
|
||||
|
||||
let die error msg =
|
||||
let backtrace = Exn.backtrace () in
|
||||
F.kasprintf (fun s -> raise_error error s backtrace) msg
|
||||
|
||||
let exit_code_of_exception = function
|
||||
| InferUserError _
|
||||
-> 1
|
||||
| InferExternalError _
|
||||
-> 3
|
||||
| InferInternalError _
|
||||
-> 4
|
||||
| _
|
||||
-> (* exit code 2 is used by the OCaml runtime in cases of uncaught exceptions *) 2
|
@ -0,0 +1,26 @@
|
||||
(*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
(* WARNING: ONLY USE IF Logging IS NOT AVAILABLE TO YOU FOR SOME REASON (e.g., inside Config). *)
|
||||
|
||||
exception InferExternalError of string * string
|
||||
|
||||
exception InferInternalError of string * string
|
||||
|
||||
exception InferUserError of string * string
|
||||
|
||||
(** kind of error for [die], with similar semantics as [Logging.{external,internal,user}_error] *)
|
||||
type error = ExternalError | InternalError | UserError
|
||||
|
||||
val exit_code_of_exception : Exn.t -> int
|
||||
|
||||
val die : error -> ('a, Format.formatter, unit, _) format4 -> 'a
|
||||
(** Raise the corresponding exception. *)
|
@ -0,0 +1,23 @@
|
||||
(*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
let erase_backtrace exn =
|
||||
match exn with
|
||||
| Logging.InferUserError (msg, _)
|
||||
-> Logging.InferUserError (msg, "")
|
||||
| Logging.InferExternalError (msg, _)
|
||||
-> Logging.InferExternalError (msg, "")
|
||||
| Logging.InferInternalError (msg, _)
|
||||
-> Logging.InferInternalError (msg, "")
|
||||
| _
|
||||
-> exn
|
||||
|
||||
let assert_raises ?msg exn f =
|
||||
OUnit2.assert_raises ?msg (erase_backtrace exn) (fun () ->
|
||||
try f ()
|
||||
with exn -> raise (erase_backtrace exn) )
|
@ -0,0 +1,14 @@
|
||||
(*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
val assert_raises : ?msg:string -> exn -> (unit -> 'a) -> unit
|
||||
(** OUnit2.assert_raises checks that a function raises some exception that's exactly the same as a
|
||||
reference exception, but some of our internal exceptions contain verbose and flaky data, eg
|
||||
backtraces. This will normalize such known exceptions by erasing their verbose data. Use this if
|
||||
you're suffering from OUnit2.assert_raises. *)
|
Loading…
Reference in new issue