From 1e6b54757d50c75fc20dc45b92ec61a7f2744ac7 Mon Sep 17 00:00:00 2001 From: Andrii Shumada Date: Thu, 27 Jun 2024 18:02:41 +0300 Subject: [PATCH 1/4] 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 --- src/resumable-upload.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resumable-upload.ts b/src/resumable-upload.ts index 5a1f71ccc..1f726f36b 100644 --- a/src/resumable-upload.ts +++ b/src/resumable-upload.ts @@ -1231,7 +1231,7 @@ 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; } @@ -1252,7 +1252,7 @@ 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)}`); } } From ed021e66d88afa297f0ddc4aae54d6d2c9e801b7 Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Mon, 8 Jul 2024 13:19:08 +0000 Subject: [PATCH 2/4] linter fixes --- src/resumable-upload.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resumable-upload.ts b/src/resumable-upload.ts index 1f726f36b..f7327e1aa 100644 --- a/src/resumable-upload.ts +++ b/src/resumable-upload.ts @@ -1252,7 +1252,9 @@ export class Upload extends Writable { } this.numRetries++; } else { - this.destroy(new Error(`Retry limit exceeded - ${JSON.stringify(resp.data)}`); + this.destroy( + new Error(`Retry limit exceeded - ${JSON.stringify(resp.data)}`) + ); } } From e1faa72ec608a92f8f2f08002cd75703ed2770b6 Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Mon, 8 Jul 2024 23:35:36 +0000 Subject: [PATCH 3/4] fix tests --- test/resumable-upload.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/resumable-upload.ts b/test/resumable-upload.ts index da3ca97bc..0080767e0 100644 --- a/test/resumable-upload.ts +++ b/test/resumable-upload.ts @@ -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(); }; @@ -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(); }); From 4e5ba9590ac8ecec5f696e84e58d8efa09cf34a2 Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Mon, 8 Jul 2024 23:37:55 +0000 Subject: [PATCH 4/4] linter fix --- src/resumable-upload.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resumable-upload.ts b/src/resumable-upload.ts index f7327e1aa..b12c27f09 100644 --- a/src/resumable-upload.ts +++ b/src/resumable-upload.ts @@ -1231,7 +1231,9 @@ export class Upload extends Writable { if (retryDelay <= 0) { this.destroy( - new Error(`Retry total time limit exceeded - ${JSON.stringify(resp.data)}`) + new Error( + `Retry total time limit exceeded - ${JSON.stringify(resp.data)}` + ) ); return; }