javascripterror-handlingruntime-errorgraaljs

List of all possible error types in JavaScript?


Is there any test suite/list of all possible errors defined by the ECMAScript spec? I am currently writing a JavaScript Runtime and I wanted to have fancy errors so I need to parse them from the engine and handle accordingly.

The engine is Graal.jS, if that matters.

Regards - Yush.


Solution

  • Is there any list of all possible errors defined by the ECMAScript spec?

    Sure, the list of possible error types is in the ECMAScript spec itself. But it seems you're only interested in SyntaxError specifically.

    Is there any list of all possible syntax errors in JavaScript?

    No. The ECMAScript specification does not mandate any specific error messages for syntax errors. Any engine is allowed to bring their own, and is also allowed to implement syntax extensions.

    The engine is Graal.jS, if that matters.

    Yes, it does matter. Graal.js does implement some syntax extensions. As for the list of possible parser error messages, you probably best look into the source code of the parser itself.

    Here's a list of errors that I extracted (dirtily with the regex /(?<=throw error\().*?(?=,[^,]*\);)/g) from the mentioned file:

    ECMAErrors.getMessage("syntax.error.redeclare.variable", varNode.getName().getName())
    AbstractParser.message("arguments.in.field.initializer")
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    String.format("unexpected node in AssignmentPattern: %s"
    String.format("nullish coalescing operator cannot immediately contain, or be contained within
    AbstractParser.message("use.strict.non.simple.param")
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "function declaration")
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "let declaration")
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "const declaration")
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "class declaration")
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "async function declaration")
    AbstractParser.message("invalid.private.ident")
    AbstractParser.message("multiple.constructors")
    AbstractParser.message("invalid.private.ident")
    AbstractParser.message("unexpected.token"
    AbstractParser.message("invalid.private.ident")
    ECMAErrors.getMessage("syntax.error.redeclare.variable", classElement.getPrivateName())
    AbstractParser.message("invalid.private.ident")
    AbstractParser.message("generator.constructor")
    AbstractParser.message("accessor.constructor")
    AbstractParser.message("async.constructor")
    AbstractParser.message("static.prototype.method")
    AbstractParser.message("private.constructor.method")
    AbstractParser.message("constructor.field")
    AbstractParser.message("static.prototype.field")
    AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
    expectMessage(IDENT, ident.getToken())
    AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
    expectMessage(IDENT, ident.getToken())
    AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
    AbstractParser.message("strict.name", ident.getName(), contextString)
    AbstractParser.message("missing.destructuring.assignment")
    AbstractParser.message("missing.const.assignment"
    ECMAErrors.getMessage("syntax.error.redeclare.variable", name)
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    "Rest element must be last"
    "Unexpected element after rest element"
    AbstractParser.message(MESSAGE_INVALID_LVALUE)
    "Unexpected element after rest element"
    "Expected a valid binding identifier"
    "Expected a valid binding identifier"
    String.format("unexpected node in BindingPattern: %s"
    AbstractParser.message("invalid.for.await.of")
    AbstractParser.message("missing.const.assignment"
    AbstractParser.message("missing.destructuring.assignment")
    AbstractParser.message("for.each.without.in")
    AbstractParser.message("many.vars.in.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
    AbstractParser.message("for.in.loop.initializer", isForOf || isForAwaitOf ? "of" : "in")
    AbstractParser.message("not.lvalue.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
    AbstractParser.message("undefined.label", ident.getName())
    AbstractParser.message("illegal.continue.stmt")
    AbstractParser.message("undefined.label", ident.getName())
    AbstractParser.message("illegal.break.stmt")
    AbstractParser.message("unexpected.token"
    AbstractParser.message("strict.no.with")
    AbstractParser.message("duplicate.label", ident.getName())
    AbstractParser.message(MESSAGE_EXPECTED_OPERAND
    AbstractParser.message("missing.catch.or.finally")
    AbstractParser.message("strict.no.nonoctaldecimal")
    AbstractParser.message("strict.no.octal")
    AbstractParser.message(MESSAGE_EXPECTED_OPERAND
    AbstractParser.message("expected.comma"
    AbstractParser.message("expected.property.id"
    AbstractParser.message("expected.comma"
    AbstractParser.message("multiple.proto.key")
    AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
    AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
    AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
    AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
    AbstractParser.message("strict.no.nonoctaldecimal")
    AbstractParser.message("strict.no.octal")
    AbstractParser.message("expected.target")
    AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
    AbstractParser.message("unexpected.token"
    AbstractParser.message("invalid.super")
    AbstractParser.message("unexpected.import.meta")
    AbstractParser.message("unexpected.ident", meta)
    AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
    AbstractParser.message(MESSAGE_EXPECTED_STMT, "generator function declaration")
    JSErrorType.SyntaxError, AbstractParser.message("strict.no.func.decl.here")
    JSErrorType.SyntaxError, AbstractParser.message("no.func.decl.here")
    AbstractParser.message("strict.param.redefinition", duplicateParameter.getName())
    AbstractParser.message("unexpected.token"
    AbstractParser.message("unexpected.token"
    AbstractParser.message("strict.cant.delete.ident", ident.getName())
    AbstractParser.message("strict.cant.delete.private")
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message("expected.arrow.parameter")
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
    AbstractParser.message("unterminated.template.expression")
    ECMAErrors.getMessage("syntax.error.redeclare.variable", ident.getName())
    AbstractParser.message("duplicate.import.assertion", assertionKey)
    AbstractParser.message("expected.binding.identifier")
    AbstractParser.message("invalid.export")
    expectMessage(IDENT, reservedWordToken)
    AbstractParser.message("new.target.in.function")