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

Fix error.stdout|stderr|all type when encoding option is used #652

Merged
merged 1 commit into from Jan 6, 2024

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Jan 6, 2024

Right now, the encoding option is not correctly applied to error.stdout|stderr|all. Namely:

  • When encoding is buffer, error.stdout|stderr|all is an ArrayBuffer instead of an Uint8Array
  • When encoding is something else like hex, error.stdout|stderr|all is a Node.js Buffer instead of a string
  • In both cases, our output normalization logic eventually transforms this to undefined

This is because the encoding logic is applied after get-stream has succeeded, but it is not applied on error.bufferedData, i.e. when get-stream has failed or been aborted.

This PR fixes this.

try {
return await streamPromise;
} catch (error) {
return error.bufferedData;
return error.bufferedData === undefined ? undefined : applyEncoding(error.bufferedData, encoding);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

error.bufferedData is undefined when the encoding option has an invalid value.

@sindresorhus sindresorhus merged commit cff6847 into main Jan 6, 2024
16 checks passed
@sindresorhus sindresorhus deleted the node-buffer-error branch January 6, 2024 21:52
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.

None yet

2 participants