Skip to content

Confusing runtime crash if scratch-vm uses async #5025

@cwillisf

Description

@cwillisf

Expected Behavior

Using the async keyword in scratch-vm should either work correctly (requires changes in scratch-gui I believe) or it should be forbidden by lint and/or webpack rules (requires changes in scratch-vm).

Ideally, any error messages caused by using unsupported features should contain information about which unsupported feature was used, and where.

Actual Behavior

If async is used anywhere in scratch-vm then scratch-gui crashes at runtime with a message similar to Uncaught ReferenceError: regeneratorRuntime is not defined.

The message may appear immediately or may be delayed, depending on where the async keyword appears in the scratch-vm source code.

In some cases the error message may indicate the location of the async keyword but in my experience it usually indicates GUI.render with a deep React stack. The message doesn't contain any indication that the problem has anything to do with async, unsupported features, or anything like that which is especially problematic when the call stack doesn't indicate the correct location either.

Steps to Reproduce

  1. In scratch-vm:
    1. Place a line like this in just about any JavaScript file under src: const _foo = async function () { };
    2. Optionally, run npm run lint and note that there are no errors.
    3. Run npm run build or npm run watch to build the modified code. Note that there are no errors.
    4. Run npm link to register this copy of scratch-vm.
  2. In scratch-gui:
    1. Run npm link scratch-vm to link to the modified scratch-vm.
    2. Run npm start to start the webpack dev server.
    3. Visit http://localhost:8601/ in a browser, ideally with the dev console open.
    4. Observe the Uncaught ReferenceError: regeneratorRuntime is not defined error in the console. Depending on where the async keyword is, you may or may not also see the "Oops! Something went wrong." screen.

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