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: don't spread error object #652

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

kanadgupta
Copy link
Contributor

@kanadgupta kanadgupta commented Nov 15, 2024

Hi there — I noticed that using spread syntax on the error object strips away a lot of helpful data that we use for our assertions so this PR helps preserve that information.

You can reproduce this by opening up a Node REPL and typing in the following:

const error1 = new TypeError('one')
console.log(error1.name)
const spread = { error: { ...error1, message: 'edited' } }
console.log(spread.error.name)

Note how the name property on the error object is lost entirely.

This PR updates this logic to use Object.assign() instead — try the following in your Node REPL and observe that the error's name information is preserved:

const error2 = new TypeError('two')
console.log(error2.name)
const assigned = { error: Object.assign(error2, { message: 'edited' }) }
console.log(assigned.error.name)

Thanks again for all your work on this library!

@kanadgupta kanadgupta changed the title fix: don't destructure error object fix: don't spread error object Nov 16, 2024
kanadgupta added a commit to readmeio/rdme that referenced this pull request Nov 16, 2024
hopefully i can get oclif/test#652 merged 🤞🏽
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant