Skip to content

Conversation

@dahiya001rohit
Copy link

This PR resolves several TODO comments related to error handling in
lib/buffer.js
and
src/node_worker.cc
to improve error reporting and debuggability.

Changes:

lib/buffer.js
:
Buffer.concat: Now throws ERR_INVALID_ARG_VALUE instead of ERR_INVALID_ARG_TYPE when a list element is not a Buffer or Uint8Array. This provides a clearer error message indicating the specific invalid value.
Buffer.byteLength: Now throws ERR_UNKNOWN_ENCODING when an unknown encoding is provided, instead of silently falling back to UTF-8.
Note: This is a semantic change. Previously, unknown encodings would default to UTF-8. This change enforces valid encodings as suggested by the code comments.
src/node_worker.cc
:
Updated
WorkerThreadData
initialization to use ExitCode::kBootstrapFailure instead of ExitCode::kGenericUserError for uv_loop_init and NewIsolate failures.
Updated Worker::NearHeapLimit to use ExitCode::kV8FatalError instead of ExitCode::kGenericUserError for out-of-memory situations.
Updated Worker::Run to use ExitCode::kBootstrapFailure for NewContext failures.
Tests:

Updated
test/parallel/test-buffer-concat.js
to expect ERR_INVALID_ARG_VALUE.
Updated
test/parallel/test-buffer-bytelength.js
to expect ERR_UNKNOWN_ENCODING.
Verified that make -j4 node builds successfully and tests pass.
Labels: buffer, worker, semver-major (due to Buffer.byteLength throwing on unknown encoding)

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support. labels Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants