From 5aae06f007ba4fb7751fc19d7ca633d9872063f3 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Thu, 15 Sep 2022 15:56:40 +0200 Subject: [PATCH] Do not display a backtrace when exiting normally 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 #398 --- CHANGES.md | 1 + src/lib/uTop_main.ml | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 84672da..145a716 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ------------------ diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index dae7724..be96f94 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -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