buffer, worker: resolve error handling TODOs #60931
Open
+84
−83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)