Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing properties, error types, and stack in @stdlib/error/reviver #6353

Closed
wants to merge 11 commits into from

Conversation

ishikajais27
Copy link

fix: handle missing properties, error types, and stack in @stdlib/error/reviver

This PR fixes three functional bugs in the @stdlib/error/reviver module that affect the correctness and reliability of the reviver function.

Bug Fixes

lib/index.js

  • Issue 1: The reviver function did not handle missing message, name, or stack properties, leading to incorrect Error objects (e.g., a message of "undefined" if value.message was undefined).
  • Fix 1: Added default values for message and name, and only set stack if it’s a string.
  • Issue 2: The function always used a generic Error constructor, ignoring the specific error type (e.g., SyntaxError, TypeError), causing the revived error to have the wrong type.
  • Fix 2: Added logic to use the appropriate error constructor based on value.name.
  • Issue 3: The function did not handle cases where the stack property is not writable or value.stack is not a string, which could cause issues in some environments.
  • Fix 3: Added checks to ensure stack is only set if value.stack is a string and the stack property is writable.

test/test.js

  • Enhancement: Added tests for edge cases (missing properties, invalid stack values, and specific error types like TypeError) to ensure the fixes are robust.

Checklist

@stdlib-bot stdlib-bot added First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review. labels Mar 24, 2025
@ishikajais27 ishikajais27 closed this by deleting the head repository Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants