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 diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts index 8151bbf18d..4399d48d69 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -202,7 +202,7 @@ describe('DefaultLocationServiceTest', () => { { type: 'url', target: 'https://backstage.io/catalog-info.yaml' }, true, ), - ).rejects.toThrowError('Duplicate nested entity: location:default/foo'); + ).rejects.toThrow('Duplicate nested entity: location:default/foo'); }); it('should return exists false when the location does not exist beforehand', async () => { @@ -270,6 +270,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', () => { diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts index 2c051a6e66..819cead63d 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -79,7 +79,7 @@ export class DefaultLocationService implements LocationService { stringifyEntityRef(processed.completedEntity), ) ) { - throw new Error( + throw new InputError( `Duplicate nested entity: ${stringifyEntityRef( processed.completedEntity, )}`, @@ -88,7 +88,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;