Skip to content

flow-parser package installs global error handler catching and re-throwing all errors. #9299

@thecrypticace

Description

@thecrypticace

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

  1. https://github.com/thecrypticace/flow-error-catching-repro
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions