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

Ensure error.bufferedData is as full as possible #106

Merged
merged 1 commit into from
Aug 17, 2023
Merged

Ensure error.bufferedData is as full as possible #106

merged 1 commit into from
Aug 17, 2023

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Aug 17, 2023

When the stream is larger than maxBuffer, the last chunk is currently missing from error.bufferedData, since it would make error.bufferedData larger than maxBuffer.

This PR adds the last chunk instead, but truncated so it fits within maxBuffer.

This has several advantages:

  1. This gives additional information to the error to help users debug the underlying issue.
  2. This prevents error.bufferedData from being empty when a single chunk was emitted and it was larger than maxBuffer. This can happen when maxBuffer is low, or when the stream highWatermark is high.
  3. This ensures error.bufferedData is always exactly the same. For example, I was trying Execa with get-stream@8 and the output of childProcess.stdout was inconsistent between test runs, since the underlying stream's chunks are timing-dependent. Therefore, the test was harder to reproduce consistently.

@sindresorhus sindresorhus merged commit f26b8a0 into sindresorhus:main Aug 17, 2023
@ehmicky ehmicky deleted the max-buffered-data branch August 17, 2023 15:23
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.

2 participants