From c8196bd37d23e3eca12930969cfb218bfd07c7c5 Mon Sep 17 00:00:00 2001 From: Manuel Stein Date: Fri, 22 Jul 2022 18:43:44 +0300 Subject: [PATCH] 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);