-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Flow version: 0.274.2 (JS)
Expected behavior
Importing flow doesn't install a global error handler that captures all errors.
Actual behavior
After importing flow-parser any uncaught thrown error is processed by a global error handler that gets installed. I think this is because of the OCaml byte code -> JS compiler (ocaml_of_js). It seems to handle errors by installing a global error handler via process.on('uncaughtException', …).
Because of this the line of code that actually threw the error isn't the one displayed. Node.js prints the source of the line inside flow that re-throws the error. Normally this is "fine" but if the module gets bundled and minified (like it does in prettier) it causes all thrown errors to be preceded by a long string cf code (tens of thousands of chars) entirely unrelated to where the error was originally thrown.
Reproduction
- https://github.com/thecrypticace/flow-error-catching-repro
- The issue is not reproducible on Try-Flow
You can reproduce it quite easily with two lines:
import "flow-parser";
throw new Error("test");
The linked repro also includes a reproduction using a minified version of flow-parser as discussed above.