diff --git a/src/file.ts b/src/file.ts index 02aa3d505..e808f5c9a 100644 --- a/src/file.ts +++ b/src/file.ts @@ -4141,8 +4141,7 @@ class File extends ServiceObject { ) { retryOptions.autoRetry = false; } - - const uploadStream = resumableUpload.upload({ + const cfg = { authClient: this.storage.authClient, apiEndpoint: this.storage.apiEndpoint, bucket: this.bucket.name, @@ -4168,7 +4167,17 @@ class File extends ServiceObject { highWaterMark: options?.highWaterMark, universeDomain: this.bucket.storage.universeDomain, [GCCL_GCS_CMD_KEY]: options[GCCL_GCS_CMD_KEY], - }); + }; + + let uploadStream: resumableUpload.Upload; + + try { + uploadStream = resumableUpload.upload(cfg); + } catch (error) { + dup.destroy(error as Error); + this.storage.retryOptions.autoRetry = this.instanceRetryValue; + return; + } uploadStream .on('response', resp => { diff --git a/test/file.ts b/test/file.ts index 46d0c125a..cfbb46597 100644 --- a/test/file.ts +++ b/test/file.ts @@ -1991,6 +1991,25 @@ describe('File', () => { writable.write('data'); }); + it('should emit RangeError', done => { + const error = new RangeError( + 'Cannot provide an `offset` without providing a `uri`' + ); + + const opitons = { + offset: 1, + isPartialUpload: true, + }; + const writable = file.createWriteStream(opitons); + + writable.on('error', (err: RangeError) => { + assert.deepEqual(err, error); + done(); + }); + + writable.write('data'); + }); + it('should emit progress via resumable upload', done => { const progress = {};