Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTop exits reporting an exception after requiring core #398

Closed
janilcgarcia opened this issue Aug 6, 2022 · 1 comment · Fixed by #399
Closed

UTop exits reporting an exception after requiring core #398

janilcgarcia opened this issue Aug 6, 2022 · 1 comment · Fixed by #399

Comments

@janilcgarcia
Copy link

Whenever I #require "core";; (core from JaneStreet) during a UTop session, I receive the following report on a #quit;;:

Raised at Topdirs.dir_quit in file "toplevel/topdirs.ml", line 66, characters 18-52
Called from Topcommon.try_run_directive in file "toplevel/topcommon.ml", line 335, characters 34-38
Called from Topeval.execute_phrase in file "toplevel/byte/topeval.ml", line 177, characters 6-42
Re-raised at Topeval.execute_phrase in file "toplevel/byte/topeval.ml", line 180, characters 4-13
Called from UTop_main.execute_phrase.(fun) in file "src/lib/uTop_main.ml", line 762, characters 14-48
Called from UTop_main.loop in file "src/lib/uTop_main.ml", line 852, characters 18-49
Re-raised at Location.report_exception.loop in file "parsing/location.ml", line 938, characters 14-25
Called from UTop.get_message in file "src/lib/uTop.ml", line 129, characters 2-11
Called from UTop_main.loop in file "src/lib/uTop_main.ml", line 871, characters 21-61
Called from UTop_main.main_aux in file "src/lib/uTop_main.ml", line 1630, characters 8-17
Called from UTop_main.main_internal in file "src/lib/uTop_main.ml", line 1646, characters 4-25

I doesn't actually cause any issue, but its annoying and it may be hiding some more troubling issue. I was not sure whether I should report the issue here or on JaneStreet's repo.

I'm using opam + ocaml 4.14.0. Here are the package versions:

astring                     0.8.5
base                        v0.15.0
base-bigarray               base
base-bytes                  base
base-threads                base
base-unix                   base
base_bigstring              v0.15.0
base_quickcheck             v0.15.0
bin_prot                    v0.15.0
camlp-streams               5.0.1
cmdliner                    1.1.1
core                        v0.15.0
core_bench                  v0.15.0
core_kernel                 v0.15.0
core_unix                   v0.15.0
cppo                        1.6.9
csexp                       1.5.1
dot-merlin-reader           4.6
dune                        3.4.1
dune-build-info             3.4.1
dune-configurator           3.4.1
either                      1.0.0
expect_test_helpers_core    v0.15.0
fieldslib                   v0.15.0
fix                         20220121
fpath                       0.7.3
int_repr                    v0.15.0
jane-street-headers         v0.15.0
jst-config                  v0.15.1
lambda-term                 3.3.1
logs                        0.7.0
lwt                         5.6.1
lwt_react                   1.2.0
menhir                      20220210
menhirLib                   20220210
menhirSdk                   20220210
merlin                      4.6-414
merlin-lib                  4.6-414
mew                         0.1.0
mew_vi                      0.5.0
num                         1.4
ocaml                       4.14.0
ocaml-base-compiler         4.14.0
ocaml-compiler-libs         v0.12.4
ocaml-config                2
ocaml-options-vanilla       1
ocaml-version               3.5.0
ocaml_intrinsics            v0.15.2
ocamlbuild                  0.14.1
ocamlfind                   1.9.5
ocamlformat                 0.24.1
ocp-indent                  1.8.1
ocplib-endian               1.2
odoc-parser                 2.0.0
parsexp                     v0.15.0
ppx_assert                  v0.15.0
ppx_base                    v0.15.0
ppx_bench                   v0.15.0
ppx_bin_prot                v0.15.0
ppx_cold                    v0.15.0
ppx_compare                 v0.15.0
ppx_custom_printf           v0.15.0
ppx_derivers                1.2.1
ppx_disable_unused_warnings v0.15.0
ppx_enumerate               v0.15.0
ppx_expect                  v0.15.0
ppx_fields_conv             v0.15.0
ppx_fixed_literal           v0.15.0
ppx_hash                    v0.15.0
ppx_here                    v0.15.0
ppx_ignore_instrumentation  v0.15.0
ppx_inline_test             v0.15.0
ppx_jane                    v0.15.0
ppx_let                     v0.15.0
ppx_log                     v0.15.0
ppx_module_timer            v0.15.0
ppx_optcomp                 v0.15.0
ppx_optional                v0.15.0
ppx_pipebang                v0.15.0
ppx_sexp_conv               v0.15.1
ppx_sexp_message            v0.15.0
ppx_sexp_value              v0.15.0
ppx_stable                  v0.15.0
ppx_string                  v0.15.0
ppx_typerep_conv            v0.15.0
ppx_variants_conv           v0.15.0
ppxlib                      0.27.0
re                          1.10.4
react                       1.2.2
result                      1.5
seq                         base
sexp_pretty                 v0.15.0
sexplib                     v0.15.1
sexplib0                    v0.15.1
spawn                       v0.15.1
splittable_random           v0.15.0
stdio                       v0.15.0
stdlib-shims                0.3.0
textutils                   v0.15.0
textutils_kernel            v0.15.0
time_now                    v0.15.0
timezone                    v0.15.0
topkg                       1.0.5
trie                        1.0.0
typerep                     v0.15.0
uchar                       0.0.2
utop                        2.10.0
uucp                        14.0.0
uuseg                       14.0.0
uutf                        1.0.3
variantslib                 v0.15.0
yojson                      2.0.1
zed                         3.2.0
@emillon
Copy link
Collaborator

emillon commented Sep 15, 2022

This is because of Backtrace.initialize_module in base. The problem can be reduced, without core, to:

utop # Printexc.record_backtrace true;;
utop # #quit;;

This differs from the behavior of the ocaml toplevel, which exits directly.

I'm not sure what's the best fix is. We can probably exit directly in the Exit_with_status case below:

utop/src/lib/uTop_main.ml

Lines 1634 to 1651 in bbd9a6e

let main_internal ~initial_env =
let exit_status = ref 2 in
try
main_aux ~initial_env
with exn ->
(match exn with
| 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

emillon added a commit to emillon/utop that referenced this issue Sep 15, 2022
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
emillon added a commit to emillon/utop that referenced this issue Sep 15, 2022
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
emillon added a commit to emillon/utop that referenced this issue Jan 5, 2023
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
emillon added a commit that referenced this issue Jan 5, 2023
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
emillon added a commit to emillon/opam-repository that referenced this issue Jan 5, 2023
CHANGES:

* Bump the compatibility to 4.08+ (ocaml-community/utop#393 @emillon)
* Load `@toplevel_printer` annotated printers for functors (ocaml-community/utop#378 @metavinek)
* Do not display a backtrace when exiting normally (ocaml-community/utop#399 ocaml-community/utop#398 @emillon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants