Skip to content

Commit

Permalink
Do not display a backtrace when exiting normally
Browse files Browse the repository at this point in the history
Exiting normally here refers to the `Exit_with_status` exception.
It is in particular triggered by `#quit;;` so we want to exit quietly
in that case.

Closes ocaml-community#398
  • Loading branch information
emillon committed Sep 15, 2022
1 parent bbd9a6e commit 8243309
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased

* Bump the compatibility to 4.08+ (#393 @emillon)
* Load `@toplevel_printer` annotated printers for functors (#378 @metavinek)
* Do not display a backtrace when exiting normally (#399 #398 @emillon)

2.10.0 (2022-10-06)
------------------
Expand Down
9 changes: 4 additions & 5 deletions src/lib/uTop_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1632,23 +1632,22 @@ let main_aux ~initial_env =
exit 0

let main_internal ~initial_env =
let exit_status = ref 2 in
try
main_aux ~initial_env
with exn ->
(match exn with
#if OCAML_VERSION >= (4,12,0)
| Compenv.Exit_with_status e -> exit e
#endif
| Unix.Unix_error (error, func, "") ->
Printf.eprintf "%s: %s: %s\n" app_name func (Unix.error_message error)
| Unix.Unix_error (error, func, arg) ->
Printf.eprintf "%s: %s(%S): %s\n" app_name func arg (Unix.error_message error)
#if OCAML_VERSION >= (4,12,0)
| Compenv.Exit_with_status e -> exit_status := e
#endif
| exn ->
Printf.eprintf "Fatal error: exception %s\n" (Printexc.to_string exn));
Printexc.print_backtrace stderr;
flush stderr;
exit !exit_status
exit 2

let main () = main_internal ~initial_env:None

Expand Down

0 comments on commit 8243309

Please sign in to comment.