Skip to content

Commit

Permalink
fix: capture and throw on non-existent files (#1969)
Browse files Browse the repository at this point in the history
* 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...
  • Loading branch information
d-goog authored May 25, 2022
1 parent 637f0b0 commit 52d81c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3922,6 +3922,7 @@ class Bucket extends ServiceObject {
writable.on('progress', options.onUploadProgress);
}
fs.createReadStream(pathString)
.on('error', bail)
.pipe(writable)
.on('error', err => {
if (
Expand Down
13 changes: 13 additions & 0 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,11 @@ describe('Bucket', () => {
describe('upload', () => {
const basename = 'testfile.json';
const filepath = path.join(__dirname, '../../test/testdata/' + basename);
const nonExistentFilePath = path.join(
__dirname,
'../../test/testdata/',
'non-existent-file'
);
const metadata = {
metadata: {
a: 'b',
Expand Down Expand Up @@ -3030,6 +3035,14 @@ describe('Bucket', () => {
}
);
});

it('should capture and throw on non-existent files', done => {
bucket.upload(nonExistentFilePath, (err: Error) => {
assert(err);
assert(err.message.includes('ENOENT'));
done();
});
});
});

describe('makeAllFilesPublicPrivate_', () => {
Expand Down

0 comments on commit 52d81c0

Please sign in to comment.