Skip to content

Commit

Permalink
fix: error serialization in resumable-upload.ts (#2493)
Browse files Browse the repository at this point in the history
* fix: use json.stringify in error reporting in resumable-upload

Existing error handling has wrong error serialization with .toString(), that leads to [object Object] error messages.
Example:
 Error: Retry limit exceeded - [object Object]
 at Upload.attemptDelayedRetry (/usr/src/app/node_modules/@google-cloud/storage/build/cjs/src/resumable-upload.js:818:26)

Better solution would be JSON.stringify the error

* linter fixes

* fix tests

* linter fix

---------

Co-authored-by: Denis DelGrosso <ddelgrosso@google.com>
  • Loading branch information
eagleeye and ddelgrosso1 authored Jul 8, 2024
1 parent 18eef67 commit c2e555c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,9 @@ export class Upload extends Writable {

if (retryDelay <= 0) {
this.destroy(
new Error(`Retry total time limit exceeded - ${resp.data}`)
new Error(
`Retry total time limit exceeded - ${JSON.stringify(resp.data)}`
)
);
return;
}
Expand All @@ -1252,7 +1254,9 @@ export class Upload extends Writable {
}
this.numRetries++;
} else {
this.destroy(new Error('Retry limit exceeded - ' + resp.data));
this.destroy(
new Error(`Retry limit exceeded - ${JSON.stringify(resp.data)}`)
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ describe('resumable-upload', () => {
up.destroy = (err: Error) => {
assert.strictEqual(
err.message,
`Retry limit exceeded - ${RESP.data}`
`Retry limit exceeded - ${JSON.stringify(RESP.data)}`
);
done();
};
Expand Down Expand Up @@ -1915,7 +1915,7 @@ describe('resumable-upload', () => {
assert.strictEqual(up.numRetries, 3);
assert.strictEqual(
err.message,
`Retry limit exceeded - ${RESP.data}`
`Retry limit exceeded - ${JSON.stringify(RESP.data)}`
);
done();
});
Expand Down

0 comments on commit c2e555c

Please sign in to comment.