Skip to content

Clarify Buffer hex string error message - #4877

Closed
jgeewax wants to merge 1 commit into
nodejs:masterfrom
jgeewax:patch-1
Closed

Clarify Buffer hex string error message#4877
jgeewax wants to merge 1 commit into
nodejs:masterfrom
jgeewax:patch-1

Conversation

@jgeewax

Copy link
Copy Markdown

Taking a clue from https://github.com/nodejs/node/blob/master/src/string_bytes.cc#L503, provide more reason for why a hex string is invalid (namely that the issue is the length being odd rather than even).

@silverwindsilverwind added the buffer Issues and PRs related to the buffer subsystem. label Jan 26, 2016
@bnoordhuis

Copy link
Copy Markdown
Member

I don't think we have a regression test for this. Can you add one to test/parallel/test-buffer.js?

Apropos the commit log, can you make sure it conforms to the guidelines from CONTRIBUTING.md? Thanks.

@mscdexmscdex added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jan 26, 2016
Comment threadsrc/node_buffer.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps, "The hex string length must be an even number" or "The hex string must have an even number of characters"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done :)

@jasnelljasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 27, 2016
@jasnell

Copy link
Copy Markdown
Member

Marking semver-major because of the error message change.

@jgeewax

Copy link
Copy Markdown
Author

@bnoordhuis I added a simple test that looks for the TypeError and (new) message.

@cjihrig

Copy link
Copy Markdown
Contributor

Can you run make lint on this, and correct the errors.

Comment threadsrc/node_buffer.cc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bnoordhuis does our C++ style allow strings split like this (the linter doesn't complain)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this should be fine.

@jgeewax

Copy link
Copy Markdown
Author

@cjihrig Did a make lint and fixed anything outstanding. Let me know if you need anything else

@cjihrig

Copy link
Copy Markdown
Contributor

The commit message should be buffer:, not buffers:, but whoever lands the commit can fix that up.

LGTM, but maybe @trevnorris wants to sign off on this?

@cjihrig

Copy link
Copy Markdown
Contributor

@jgeewax

Copy link
Copy Markdown
Author

@cjihrig : Fixed. I was going off the commit log, which seemed to have both. Sorry about that.

@cjihrig

Copy link
Copy Markdown
Contributor

Looks like a commit just landed that conflicts with this one. Mind rebasing?

@jgeewax

Copy link
Copy Markdown
Author

No problem. Let me know if that works for you.

@trevnorris

Copy link
Copy Markdown
Contributor

Is this the only location we throw for incorrect hex string length? If so then LGTM.

Comment threadtest/parallel/test-buffer.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor nit: /^The hex string must have an even number of characters/.test(err.message)

@jasnell

jasnell commented Feb 1, 2016

Copy link
Copy Markdown
Member

LGTM with a couple of nits

@jasnell

Copy link
Copy Markdown
Member

@jgeewax ... ping. There were a few nits that need to be looked at.

@jgeewax
jgeewaxforce-pushed the patch-1 branch 2 times, most recently from be3d46b to df3fe4fCompareMarch 27, 2016 16:14
@jgeewax

Copy link
Copy Markdown
Author

OK -- Addressed the console.log stuff as well as the nit for regex checking vs equality.

@jasnell

jasnell commented Mar 27, 2016

Copy link
Copy Markdown
Member

LGTM

Comment threadtest/parallel/test-buffer.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor nit: can you update this to use Buffer.from('8', 'hex')

This was referenced Jul 7, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bufferIssues and PRs related to the buffer subsystem.c++Issues and PRs that require attention from people who are familiar with C++.semver-majorPRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@jgeewax@bnoordhuis@jasnell@cjihrig@trevnorris@addaleax@MylesBorins@gibfahn@fhinkel@mscdex@silverwind