How do I get proper backtraces when running script with ocaml?
For example I have test.ml
let f () = failwith "test"
let proc () = f ()
let () = proc ()
When I run ocaml with env OCAMLRUNPARAM=b ocaml test.ml I get
Exception: Failure "test".
Raised at file "stdlib.ml", line 29, characters 22-33
Called from unknown location
Called from file "toplevel/toploop.ml", line 212, characters 17-27
I noticed that I get proper backtrace for my actual script when I #use script.ml in toplevel. That doesn’t work for the test script above though. My actual script rises Exception: Invalid_argument "index out of bounds"
Tried both OCAMLRUNPARAM=b and OCAMLRUNPARAM=b. These do enable collecting backtraces, but I get Called from unknown location instead of proper location in my script.
This appears to be a regression in OCaml 4.08. Older OCaml versions (starting from 4.03) would correctly show backtraces for script files run through ocaml. @Serpent7776, would you care to open an issue on the OCaml bugtracker, or would you prefer if I did it myself?