Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 52d81c0

Browse files
authored
fix: capture and throw on non-existent files (#1969)
* fix: capture and throw on non-existent files * fix: use event handler instead of `pipeline` - TS doesn't support the pipeline `value` return in the callback yet...
1 parent 637f0b0 commit 52d81c0

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/bucket.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,6 +3922,7 @@ class Bucket extends ServiceObject {
39223922
writable.on('progress', options.onUploadProgress);
39233923
}
39243924
fs.createReadStream(pathString)
3925+
.on('error', bail)
39253926
.pipe(writable)
39263927
.on('error', err => {
39273928
if (

test/bucket.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,11 @@ describe('Bucket', () => {
26022602
describe('upload', () => {
26032603
const basename = 'testfile.json';
26042604
const filepath = path.join(__dirname, '../../test/testdata/' + basename);
2605+
const nonExistentFilePath = path.join(
2606+
__dirname,
2607+
'../../test/testdata/',
2608+
'non-existent-file'
2609+
);
26052610
const metadata = {
26062611
metadata: {
26072612
a: 'b',
@@ -3030,6 +3035,14 @@ describe('Bucket', () => {
30303035
}
30313036
);
30323037
});
3038+
3039+
it('should capture and throw on non-existent files', done => {
3040+
bucket.upload(nonExistentFilePath, (err: Error) => {
3041+
assert(err);
3042+
assert(err.message.includes('ENOENT'));
3043+
done();
3044+
});
3045+
});
30333046
});
30343047

30353048
describe('makeAllFilesPublicPrivate_', () => {

0 commit comments

Comments
 (0)