Repository navigation
fix(web-api): reject files.uploadV2 when the file stream errors - #2881
Open
ranjithguggilla wants to merge 1 commit into
Open
ranjithguggilla wants to merge 1 commit into
ranjithguggilla wants to merge 1 commit into
Conversation
getFileDataAsStream only listened for "readable" and "end", so a stream that failed (for example fs.createReadStream on a missing path) emitted an unhandled "error" event. The process got an uncaught exception, or, when the stream already had an error listener, the upload promise never settled. Reject with WebAPIFileUploadReadFileDataError and keep the stream error as the cause.
🦋 Changeset detectedLatest commit: 59d18fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
mwbrooks
reviewed
Nov 23, 2026
mwbrooks
left a comment
Member
There was a problem hiding this comment.
Thanks @ranjithguggilla, and congrats on your first contribution to node-slack-sdk! 🎉 The fix looks good to me. I'll approve once CI passes.
| } | ||
| }); | ||
| // without this listener a failing stream is an uncaught exception and the promise never settles | ||
| readable.on('error', (err: Error) => { |
Member
There was a problem hiding this comment.
praise: Thanks for catching this! Keeping the stream error as cause makes the ENOENT easy to find for anyone debugging an upload.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
files.uploadV2accepts aReadableforfile, butgetFileDataAsStreamonly listened forreadableandend. A stream that fails has noerrorhandler.file: fs.createReadStream('missing.txt')ends the process with an uncaughtENOENT. Atry/catcharoundawait client.files.uploadV2(...)does not see it. If the stream already has anerrorlistener, the process stays up and the promise never settles.This listens for
errorand rejects withWebAPIFileUploadReadFileDataError, keeping the stream error ascause. That class fits because the argument is a valid stream and the read is what failed. A path string that cannot be read still throwsWebAPIFileUploadInvalidArgumentsError.A stream that has already emitted
errorbeforeuploadV2is called still never settles. That event is gone by the time the listener is attached, and this change does not cover it.Tests in
file-upload.test.ts: a missing file throughgetFileData, an error before any data, and an error after the first chunk. Those three fail onmainand pass with this change.Checked on macOS. Node 22.22.2:
npm run build,npm run lint, andnpm testfor the repo. Node 24.21.0:npm test --workspace=packages/web-api(160 passed). Not run: Node 20, Node 26, Windows, coverage, or a real Slack API call. The repro fails while reading the stream, before any request.Requirements