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);