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

src: add ERR_* helpers in C++ and migrates toString() errors in string_bytes.cc #19739

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

Another take of #19465 , this one puts the ERR_* helpers in the node namespace and put them inside node_errors.h instead of mingle them with the environment code.

Also fixes the long-standing issue of error messages in buf.toString failures by migrating them to the new error system.

The first commit is taken from #19738

Fixes: #3175
Fixes: #9489

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Apr 2, 2018
@joyeecheung
Copy link
Member Author

cc @addaleax

@joyeecheung
Copy link
Member Author

@joyeecheung joyeecheung added the semver-major PRs that contain breaking changes and should be released in the next major version. label Apr 2, 2018
v8::Local<v8::Object> e = \
v8::Exception::type(js_msg)->ToObject( \
isolate->GetCurrentContext()).ToLocalChecked(); \
e->Set(OneByteString(isolate, "code"), js_code); \
Copy link
Member

Choose a reason for hiding this comment

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

This should also be the overload that takes a context argument :)

@joyeecheung
Copy link
Member Author

Replace the deprecated API with the one that takes the context per suggestion by @addaleax , thanks!

CI: https://ci.nodejs.org/job/node-test-pull-request/14029/

@joyeecheung
Copy link
Member Author

joyeecheung commented Apr 4, 2018

Looks like on Linux PPCBE we need to ensure an extra copy of memory available for reordering..fixed the test. New CI: https://ci.nodejs.org/job/node-test-pull-request/14030/
CI: https://ci.nodejs.org/job/node-test-pull-request/14036/

EDIT: the usage of vector::assign makes the memory usage of UCS2 string slice on BE systems unpredictable...try to use constant allocation instead.
CI: https://ci.nodejs.org/job/node-test-pull-request/14042/
CI: https://ci.nodejs.org/job/node-test-pull-request/14046/

CI: https://ci.nodejs.org/job/node-test-pull-request/14050/

@joyeecheung joyeecheung force-pushed the tostring-err branch 2 times, most recently from a9fc7b5 to b416589 Compare April 4, 2018 13:27
@joyeecheung joyeecheung added the blocked PRs that are blocked by other issues or PRs. label Apr 5, 2018
joyeecheung added a commit that referenced this pull request Apr 7, 2018
Currently calling StringBytes::Encode on a UCS2 buffer
results in two copies of the buffer and the usage of
std::vector::assign makes the memory usage unpredictable,
and therefore hard to test against.

This patch makes the memory usage more predictable by
allocating the memory using node::UncheckedMalloc and
handles the memory allocation failure properly. Only
one copy of the buffer will be created and it will
be freed upon GC of the string.

PR-URL: #19798
Refs: #19739
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@joyeecheung joyeecheung removed the blocked PRs that are blocked by other issues or PRs. label Apr 7, 2018
This commit adds node::ERR_*(isolate, message) helpers in
the C++ land to assign error codes to existing C++ errors.

The following errors are added:

- ERR_MEMORY_ALLOCATION_FAILED
- ERR_STRING_TOO_LARGE
@joyeecheung
Copy link
Member Author

Landed in 1f29963...63eb267, thanks!

@joyeecheung joyeecheung closed this Apr 7, 2018
joyeecheung added a commit that referenced this pull request Apr 7, 2018
This commit adds node::ERR_*(isolate, message) helpers in
the C++ land to assign error codes to existing C++ errors.

The following errors are added:

- ERR_MEMORY_ALLOCATION_FAILED
- ERR_STRING_TOO_LARGE

PR-URL: #19739
Fixes: #3175
Fixes: #9489
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
joyeecheung added a commit that referenced this pull request Apr 7, 2018
PR-URL: #19739
Fixes: #3175
Fixes: #9489
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Apr 9, 2018
The old error name and message were trying to be consistent with
ERR_BUFFER_TOO_LARGE but they were not really accurate.
The kStringMaxLength was measured in number of characters,
not number of bytes. The name ERR_STRING_TOO_LARGE also
seems a bit awkward. This patch tries to correct them before
they get released to users.

PR-URL: nodejs#19864
Refs: nodejs#19739
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
targos pushed a commit that referenced this pull request Apr 12, 2018
Currently calling StringBytes::Encode on a UCS2 buffer
results in two copies of the buffer and the usage of
std::vector::assign makes the memory usage unpredictable,
and therefore hard to test against.

This patch makes the memory usage more predictable by
allocating the memory using node::UncheckedMalloc and
handles the memory allocation failure properly. Only
one copy of the buffer will be created and it will
be freed upon GC of the string.

PR-URL: #19798
Refs: #19739
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
5 participants