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

Truncate error.bufferedData if too large #68

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Truncate error.bufferedData if too large #68

merged 1 commit into from
Aug 8, 2023

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Aug 8, 2023

When error.bufferedData is too large, it is not set instead.
With this PR, error.bufferedData is still set, but with a smaller string/buffer. If the stream is too large, having the first bytes of it can prove to be very useful for debugging.

try {
return getBufferedValue(chunks.slice(0, chunksCount), isBuffer);
} catch {}
} while (chunksCount > 0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

chunksCount > 0 should never be false, since when chunksCount = 0 is called, chunks.slice(0, 0) will be an empty string/buffer, which is guaranteed not to throw.
So, one could use while (true) instead. I have used chunksCount > 0 instead to avoid some linting warning, and as an additional safety net to avoid infinite loops, just in case.

@ehmicky ehmicky marked this pull request as draft August 8, 2023 00:52
@ehmicky ehmicky marked this pull request as ready for review August 8, 2023 01:31
index.d.ts Outdated
*/
readonly encoding?: EncodingType;
} & Options;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of this PR's changes are from #69 (see PR description).

@sindresorhus
Copy link
Owner

Conflict

@ehmicky
Copy link
Collaborator Author

ehmicky commented Aug 8, 2023

Fixed 👍

@sindresorhus sindresorhus merged commit 82a194d into sindresorhus:main Aug 8, 2023
3 checks passed
@ehmicky ehmicky deleted the truncate-buffered-data branch August 8, 2023 18:59
@ehmicky ehmicky mentioned this pull request Aug 13, 2023
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