Skip to content

fix(web-api): reject files.uploadV2 when the file stream errors - #2881

Open
ranjithguggilla wants to merge 1 commit into
slackapi:mainfrom
ranjithguggilla:fix/web-api-upload-stream-error
Open

ranjithguggilla wants to merge 1 commit into
slackapi:mainfrom
ranjithguggilla:fix/web-api-upload-stream-error

Conversation

@ranjithguggilla

Copy link
Copy Markdown

Summary

files.uploadV2 accepts a Readable for file, but getFileDataAsStream only listened for readable and end. A stream that fails has no error handler.

file: fs.createReadStream('missing.txt') ends the process with an uncaught ENOENT. A try/catch around await client.files.uploadV2(...) does not see it. If the stream already has an error listener, the process stays up and the promise never settles.

This listens for error and rejects with WebAPIFileUploadReadFileDataError, keeping the stream error as cause. That class fits because the argument is a valid stream and the read is what failed. A path string that cannot be read still throws WebAPIFileUploadInvalidArgumentsError.

A stream that has already emitted error before uploadV2 is 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 through getFileData, an error before any data, and an error after the first chunk. Those three fail on main and pass with this change.

Checked on macOS. Node 22.22.2: npm run build, npm run lint, and npm test for 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

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.
@ranjithguggilla
ranjithguggilla requested a review from a team as a code owner November 20, 2026 23:42
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 59d18fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@slack/web-api Patch

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 mwbrooks added this to the web-api@next milestone Nov 21, 2026
@mwbrooks mwbrooks added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch pkg:web-api applies to `@slack/web-api` labels Nov 21, 2026

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented cla:signed pkg:web-api applies to `@slack/web-api` semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants