From a7810510fc986e874f3bb0a68e405057e4ef6e0c Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Wed, 22 May 2024 10:13:30 +0200 Subject: [PATCH] fix: handle missing orgEnabled config key gracefully by logging and returning early. Fixes #24857 Signed-off-by: ElaineDeMattosSilvaB --- .../GitlabOrgDiscoveryEntityProvider.test.ts | 14 +++++++------- .../providers/GitlabOrgDiscoveryEntityProvider.ts | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts index dfbf39267f..5a60f1b4b3 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.test.ts @@ -75,16 +75,16 @@ describe('GitlabOrgDiscoveryEntityProvider - configuration', () => { }).toThrow('No gitlab integration found that matches host example.com'); }); - it('should throw error when org configuration not found', () => { + it('should log a message and return when org configuration not found', () => { const schedule = new PersistingTaskRunner(); const config = new ConfigReader(mock.config_no_org_integration); - expect(() => { - GitlabOrgDiscoveryEntityProvider.fromConfig(config, { - logger, - schedule, - }); - }).toThrow('Org not enabled for test-id'); + GitlabOrgDiscoveryEntityProvider.fromConfig(config, { + logger, + schedule, + }); + + expect(logger.info).toHaveBeenCalledWith('Org not enabled for test-id.'); }); it('should throw error when saas without group configuration', () => { diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts index 0135c7b4a9..e10f9ee313 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabOrgDiscoveryEntityProvider.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { LoggerService } from '@backstage/backend-plugin-api'; import { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks'; import { ANNOTATION_LOCATION, @@ -28,7 +29,6 @@ import { import { EventsService } from '@backstage/plugin-events-node'; import { merge } from 'lodash'; import * as uuid from 'uuid'; -import { LoggerService } from '@backstage/backend-plugin-api'; import { GitLabClient, @@ -133,7 +133,8 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider { const integration = integrations.byHost(providerConfig.host); if (!providerConfig.orgEnabled) { - throw new Error(`Org not enabled for ${providerConfig.id}.`); + options.logger.info(`Org not enabled for ${providerConfig.id}.`); + return; } if (!integration) {