From c8196bd37d23e3eca12930969cfb218bfd07c7c5 Mon Sep 17 00:00:00 2001 From: Manuel Stein Date: Fri, 22 Jul 2022 18:43:44 +0300 Subject: [PATCH 1/4] wrap aws-sdk errors because there are http errors with no message any error reading the object is wrapped to conform to the @backstage/error assertError checks Signed-off-by: Manuel Stein --- .changeset/loud-panthers-arrive.md | 7 +++++++ plugins/techdocs-node/src/stages/publish/awsS3.test.ts | 2 +- plugins/techdocs-node/src/stages/publish/awsS3.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/loud-panthers-arrive.md diff --git a/.changeset/loud-panthers-arrive.md b/.changeset/loud-panthers-arrive.md new file mode 100644 index 0000000000..76e6812b5b --- /dev/null +++ b/.changeset/loud-panthers-arrive.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-techdocs-node': patch +--- + +Fix AWS S3 404 NotFound error + +When reading an object from the S3 bucket through a stream, the aws-sdk getObject() API may throw a 404 NotFound Error with no error message or, in fact, any sort of HTTP-layer error responses. These fail the @backstage/error's assertError() checks, so they must be wrapped. The test for this case was also updated to match the wrapped error message. \ No newline at end of file diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts index 6372093c4b..24ea9af563 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts @@ -478,7 +478,7 @@ describe('AwsS3Publish', () => { await expect(fails).rejects.toMatchObject({ message: expect.stringMatching( - /TechDocs metadata fetch failed; caused by Error: The file .* does not exist/i, + /TechDocs metadata fetch failed; caused by Error: .*/i, ), }); }); diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.ts b/plugins/techdocs-node/src/stages/publish/awsS3.ts index e5914d2fdf..d3456b7f21 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.ts @@ -49,7 +49,7 @@ const streamToBuffer = (stream: Readable): Promise => { try { const chunks: any[] = []; stream.on('data', chunk => chunks.push(chunk)); - stream.on('error', reject); + stream.on('error', (e: Error) => reject(new ForwardedError('Unable to read stream', e))); stream.on('end', () => resolve(Buffer.concat(chunks))); } catch (e) { throw new ForwardedError('Unable to parse the response data', e); From 6c118dd093eea6f96004bb8ee3a48a8391dcdb8d Mon Sep 17 00:00:00 2001 From: Manuel Stein Date: Sat, 23 Jul 2022 18:34:57 +0300 Subject: [PATCH 2/4] wrap aws-sdk errors - (prettier update) there are http errors with no message from aws-sdk, so the error is wrapped to conform to the @backstage/errors assertError checks Signed-off-by: Manuel Stein --- .changeset/loud-panthers-arrive.md | 2 +- plugins/techdocs-node/src/stages/publish/awsS3.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.changeset/loud-panthers-arrive.md b/.changeset/loud-panthers-arrive.md index 76e6812b5b..a8c69cdc76 100644 --- a/.changeset/loud-panthers-arrive.md +++ b/.changeset/loud-panthers-arrive.md @@ -4,4 +4,4 @@ Fix AWS S3 404 NotFound error -When reading an object from the S3 bucket through a stream, the aws-sdk getObject() API may throw a 404 NotFound Error with no error message or, in fact, any sort of HTTP-layer error responses. These fail the @backstage/error's assertError() checks, so they must be wrapped. The test for this case was also updated to match the wrapped error message. \ No newline at end of file +When reading an object from the S3 bucket through a stream, the aws-sdk getObject() API may throw a 404 NotFound Error with no error message or, in fact, any sort of HTTP-layer error responses. These fail the @backstage/error's assertError() checks, so they must be wrapped. The test for this case was also updated to match the wrapped error message. diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.ts b/plugins/techdocs-node/src/stages/publish/awsS3.ts index d3456b7f21..12940e0117 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.ts @@ -49,7 +49,9 @@ const streamToBuffer = (stream: Readable): Promise => { try { const chunks: any[] = []; stream.on('data', chunk => chunks.push(chunk)); - stream.on('error', (e: Error) => reject(new ForwardedError('Unable to read stream', e))); + stream.on('error', (e: Error) => + reject(new ForwardedError('Unable to read stream', e)), + ); stream.on('end', () => resolve(Buffer.concat(chunks))); } catch (e) { throw new ForwardedError('Unable to parse the response data', e); From f28ad77d119c9bdabf8ec9d191cc04d440e45b58 Mon Sep 17 00:00:00 2001 From: Manuel Stein Date: Sun, 24 Jul 2022 19:12:39 +0300 Subject: [PATCH 3/4] awsS3 getObject expect specific error message Signed-off-by: Manuel Stein --- plugins/techdocs-node/src/stages/publish/awsS3.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts index 24ea9af563..10f92dc074 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts @@ -478,7 +478,7 @@ describe('AwsS3Publish', () => { await expect(fails).rejects.toMatchObject({ message: expect.stringMatching( - /TechDocs metadata fetch failed; caused by Error: .*/i, + /TechDocs metadata fetch failed; caused by Error: Unable to read stream; caused by Error: The file invalid\/triplet\/path\/techdocs_metadata.json does not exist/i, ), }); }); From ce7219ff873f89f7be069f76b13991ba93894816 Mon Sep 17 00:00:00 2001 From: Manuel Stein Date: Sun, 24 Jul 2022 19:19:29 +0300 Subject: [PATCH 4/4] awsS3 getObject expect match without regex Signed-off-by: Manuel Stein --- plugins/techdocs-node/src/stages/publish/awsS3.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts index 10f92dc074..1ca9cf2abf 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.test.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.test.ts @@ -478,7 +478,7 @@ describe('AwsS3Publish', () => { await expect(fails).rejects.toMatchObject({ message: expect.stringMatching( - /TechDocs metadata fetch failed; caused by Error: Unable to read stream; caused by Error: The file invalid\/triplet\/path\/techdocs_metadata.json does not exist/i, + 'TechDocs metadata fetch failed; caused by Error: Unable to read stream; caused by Error: The file invalid/triplet/path/techdocs_metadata.json does not exist', ), }); });