Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle unhandled error in startResumableUpload_ #2495

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4141,8 +4141,7 @@ class File extends ServiceObject<File, FileMetadata> {
) {
retryOptions.autoRetry = false;
}

const uploadStream = resumableUpload.upload({
const cfg = {
authClient: this.storage.authClient,
apiEndpoint: this.storage.apiEndpoint,
bucket: this.bucket.name,
Expand All @@ -4168,7 +4167,17 @@ class File extends ServiceObject<File, FileMetadata> {
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 => {
Expand Down
19 changes: 19 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
Loading