Skip to content

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.

gurus00 pushed a commit to gurus00/stripe-node that referenced this pull request Feb 11, 2025
Handle Buffer.from TypeError on node versions prior to 4.5.x
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