Skip to content

JSError.ThrowTypeError / ThrowRangeError / ThrowSyntaxError throw a plain Error #509

Open

Description

@r-Larch

The string overloads of the typed throw helpers in src/NodeApi/JSError.cs all call JSRuntime.ThrowError:

public static void ThrowTypeError(string message)
    => JSValue.GetCurrentRuntime(out napi_env env).ThrowError(env, code: null, message);   // should be ThrowTypeError

The same applies to ThrowTypeError(code, message), ThrowRangeError(message), ThrowRangeError(code, message), ThrowSyntaxError(message) and ThrowSyntaxError(code, message). JS therefore receives an Error:

try { dotnetCallbackThatCallsThrowTypeError(); }
catch (e) {
  e instanceof TypeError; // false
  e.name;                 // 'Error'
}

JSRuntime already has ThrowTypeError, ThrowRangeError and ThrowSyntaxError (napi_throw_type_error, napi_throw_range_error, node_api_throw_syntax_error); they just are not called. Fix: call the matching runtime method. I have a PR with a test that checks name, instanceof, message and code for all four error types.

Version: main (54d2b74), 0.9.21 and 0.9.28.

Activity

  1. added a commit that references this issue on Oct 29, 2026
    21fcb80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions