From cdcf596fdef9680eec4fc0e7d91f25f18527ceb6 Mon Sep 17 00:00:00 2001 From: Dede Hamzah Date: Thu, 7 Jul 2022 14:14:37 +0700 Subject: [PATCH 1/4] Update Wrong Error Code in Register Component DryRun The error code for input validation should not default to 500 Signed-off-by: Dede Hamzah --- plugins/catalog-backend/src/service/DefaultLocationService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts index fc6ffb0825..e481f3d949 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -81,7 +81,7 @@ export class DefaultLocationService implements LocationService { stringifyEntityRef(processed.completedEntity), ) ) { - throw new Error( + throw new InputError( `Duplicate nested entity: ${stringifyEntityRef( processed.completedEntity, )}`, @@ -90,7 +90,7 @@ export class DefaultLocationService implements LocationService { unprocessedEntities.push(...processed.deferredEntities); entities.push(processed.completedEntity); } else { - throw Error(processed.errors.map(String).join(', ')); + throw new InputError(processed.errors.map(String).join(', ')); } } return entities; From eb91937a92502ee98dc0e06716d2ea04333642fb Mon Sep 17 00:00:00 2001 From: Dede Hamzah Date: Mon, 11 Jul 2022 15:05:18 +0700 Subject: [PATCH 2/4] Add tests Signed-off-by: Dede Hamzah --- .../service/DefaultLocationService.test.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index bd166cbd50..debf2e4b2f 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -197,7 +197,7 @@ describe('DefaultLocationServiceTest', () => { { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, ), - ).rejects.toThrowError('Duplicate nested entity: location:default/foo'); + ).rejects.toThrow(InputError); }); it('should return exists false when the location does not exist beforehand', async () => { @@ -264,6 +264,25 @@ describe('DefaultLocationServiceTest', () => { ), ).rejects.toThrow(InputError); }); + + it('should return default InputError for failed processed entities in dryRun mode', async () => { + store.listLocations.mockResolvedValueOnce([]); + + orchestrator.process.mockResolvedValueOnce({ + ok: false, + errors: [new Error('Error: Unable to read url')], + }); + + await expect( + locationService.createLocation( + { + type: 'url', + target: 'https://backstage.io/wrong-url/catalog-info.yaml', + }, + true, + ), + ).rejects.toThrow(InputError); + }); }); describe('listLocations', () => { From 5f6b847c15b4cf8062c8c3fc3ba7b3989dc0522f Mon Sep 17 00:00:00 2001 From: Dede Hamzah Date: Mon, 11 Jul 2022 15:08:07 +0700 Subject: [PATCH 3/4] add changeset Signed-off-by: Dede Hamzah --- .changeset/breezy-spiders-eat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/breezy-spiders-eat.md diff --git a/.changeset/breezy-spiders-eat.md b/.changeset/breezy-spiders-eat.md new file mode 100644 index 0000000000..d163fc365f --- /dev/null +++ b/.changeset/breezy-spiders-eat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Fix Error Code in Register Component DryRun From 13506d50228a4dcfbf5fd952ca3a80e8e66c4f96 Mon Sep 17 00:00:00 2001 From: Dede Hamzah Date: Tue, 12 Jul 2022 09:02:40 +0700 Subject: [PATCH 4/4] Revert throw message and use .toThrow Signed-off-by: Dede Hamzah --- .../catalog-backend/src/service/DefaultLocationService.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index debf2e4b2f..23eea88b9a 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -197,7 +197,7 @@ describe('DefaultLocationServiceTest', () => { { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, ), - ).rejects.toThrow(InputError); + ).rejects.toThrow('Duplicate nested entity: location:default/foo'); }); it('should return exists false when the location does not exist beforehand', async () => {