Skip to content

fix: Add Error constructors to NodeVM context to fix jsonwebtoken test failures#6209

Merged
bijin-bruno merged 1 commit intousebruno:mainfrom
chirag-bruno:bugfix/jwt-signing-fail
Nov 26, 2025
Merged

fix: Add Error constructors to NodeVM context to fix jsonwebtoken test failures#6209
bijin-bruno merged 1 commit intousebruno:mainfrom
chirag-bruno:bugfix/jwt-signing-fail

Conversation

@chirag-bruno
Copy link
Collaborator

Description

When running jsonwebtoken tests with the NodeVM runtime, tests were failing because instanceOf(Error) checks were returning false. This occurred because:

  • Errors thrown by jsonwebtoken inside the NodeVM context were instances of the VM's isolated Error class
  • Tests checking expect(err).to.be.instanceOf(Error) were comparing against the outer context's Error class
  • These are different Error classes, causing the instanceOf checks to fail

Added Error constructors from the global scope to the NodeVM scriptContext:

  • Error
  • TypeError
  • ReferenceError
  • SyntaxError
  • RangeError

This ensures that errors thrown by jsonwebtoken and other modules inside the NodeVM context use the same Error class that tests check against, making instanceOf(Error) checks pass correctly.

This PR fixes: https://usebruno.atlassian.net/browse/BRU-2083

Screenshot

image

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

When jsonwebtoken throws errors inside the NodeVM context, those errors
were instances of the VM's isolated Error class, which caused
instanceOf(Error) checks in tests to fail.

By adding Error constructors (Error, TypeError, ReferenceError,
SyntaxError, RangeError) from the global scope to the scriptContext,
errors thrown by jsonwebtoken and other modules now use the same Error
class that tests check against, ensuring instanceOf checks pass correctly.

This fixes jsonwebtoken test failures when using the NodeVM runtime.
@bijin-bruno bijin-bruno merged commit 7ed474c into usebruno:main Nov 26, 2025
7 checks passed
naman-bruno pushed a commit to naman-bruno/bruno that referenced this pull request Nov 27, 2025
…sebruno#6209)

When jsonwebtoken throws errors inside the NodeVM context, those errors
were instances of the VM's isolated Error class, which caused
instanceOf(Error) checks in tests to fail.

By adding Error constructors (Error, TypeError, ReferenceError,
SyntaxError, RangeError) from the global scope to the scriptContext,
errors thrown by jsonwebtoken and other modules now use the same Error
class that tests check against, ensuring instanceOf checks pass correctly.

This fixes jsonwebtoken test failures when using the NodeVM runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants