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

Handle Buffer.from TypeError on node versions prior to 4.5.x #365

Merged
merged 1 commit into from
Aug 3, 2017

Conversation

cxam
Copy link
Contributor

@cxam cxam commented Aug 2, 2017

The tests are currently failing on node v4 and versions prior to v4.5.x due to a mismatch in the Buffer.from API. This was fixed in nodejs/node#7562 and backported to v4.5.x. PR fixes the current use of the function by handling the TypeError being thrown.

Alternative solutions:

  • Exclude the failing node versions in package.json
  • Use semver checking to use the correct API instead of handling the exception

try {
return Buffer.from(thing);
} catch (e) {
if (e instanceof TypeError) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying to minimize the scope of errors that we'll try to catch.

@brandur-stripe
Copy link
Contributor

Thanks @cxam! This works for me.

@brandur-stripe brandur-stripe merged commit a9effc9 into stripe:master Aug 3, 2017
@brandur-stripe
Copy link
Contributor

Released as 4.23.2.

@cxam
Copy link
Contributor Author

cxam commented Aug 3, 2017

That's great @brahn-stripe, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants