improve excn printing
commitc82bd3d1cfa84f0d449bd2c94ca76e446576b0b8
authorLucian Wischik <ljw@fb.com>
Thu, 17 Mar 2022 16:08:06 +0000 (17 09:08 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Mar 2022 16:08:06 +0000 (17 09:08 -0700)
tree469cde2d5f4287dab48fdf2916de4b28dec56499
parentde4480c4247fd7f79607dfeb6ba87903ebc9797f
improve excn printing

Summary:
This diff changes two things...

(1) The Exception.clean_stack method used to only preserve filenames of the form ".../hack/src/...", but dune builds produce stack filenames of the form "src/...". This diff changes to accept the dune form as well.

THIS IS AN EXPERIMENT. I don't know if it will work out well. To explain the idea, look at this:
```
Called from Base__List0.fold in file "src/list0.ml" (inlined), line 21, characters 22-52
Called from Dune__exe__Fiddle.inner in file "src/ftrial/fiddle.ml" (inlined), line 13, characters 10-66
```
The conceit in this diff is that there's a small finite number of modules (like Base_List0.fold above) that come from stdlib-like, and all the rest must come from user code. The ones I've observed so far in callstacks are `Base.*, Stdlib.*, Lwt.*`. I figure there are probably just a small number of other stdlib-like modules, and I'll add them piecemeal, until we're done.

If I'm wrong about this, and over the coming weeks or months then there are just too many stdlib-like modules, then I'll have to give up on this approach.

(2) In jsonrpc.ml it used to have this code
```
let message = Printexc.to_string e in
let stack = Printexc.get_backtrace () in
```
but I discovered that the first call to Printexc.to_string had the potential to corrupt the global mutable stacktrace variable. This diff switches around the order so as to get the correct stacktrace.

Reviewed By: Wilfred

Differential Revision: D34839234

fbshipit-source-id: a24b68b5f230c433aec4ced123f76f7dbaa059c0
hphp/hack/src/utils/core/exception.ml
hphp/hack/src/utils/jsonrpc/jsonrpc.ml
hphp/hack/test/unit/utils/exception_test.ml