diff --git a/src/lib/features/feature-toggle/feature-toggle-service.ts b/src/lib/features/feature-toggle/feature-toggle-service.ts index 6a42310171..4bc977e6e8 100644 --- a/src/lib/features/feature-toggle/feature-toggle-service.ts +++ b/src/lib/features/feature-toggle/feature-toggle-service.ts @@ -1168,19 +1168,31 @@ class FeatureToggleService { projectId: string, featureNames: string[], ): Promise { - const project = await this.projectStore.get(projectId); - const patternData = project.featureNaming; - const namingPattern = patternData?.pattern; + try { + const project = await this.projectStore.get(projectId); - if (namingPattern) { - const result = checkFeatureFlagNamesAgainstPattern( - featureNames, - namingPattern, + const patternData = project.featureNaming; + const namingPattern = patternData?.pattern; + + if (namingPattern) { + const result = checkFeatureFlagNamesAgainstPattern( + featureNames, + namingPattern, + ); + + if (result.state === 'invalid') { + return { ...result, featureNaming: patternData }; + } + } + } catch (error) { + // the project doesn't exist, so there's nothing to + // validate against + this.logger.info( + "Got an error when trying to validate flag naming patterns. It is probably because the target project doesn't exist. Here's the error:", + error.message, ); - if (result.state === 'invalid') { - return { ...result, featureNaming: patternData }; - } + return { state: 'valid' }; } return { state: 'valid' }; diff --git a/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts b/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts index 0093f71b18..c27e36f686 100644 --- a/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts +++ b/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts @@ -641,6 +641,20 @@ describe('flag name validation', () => { ).resolves.toBeFalsy(); } }); + + test("should allow anything if the project doesn't exist", async () => { + const projectId = 'project-that-doesnt-exist'; + const validFeatures = ['testpattern-feature', 'testpattern-feature2']; + + for (const feature of validFeatures) { + await expect( + service.validateFeatureFlagNameAgainstPattern( + feature, + projectId, + ), + ).resolves.toBeFalsy(); + } + }); }); test('Should return last seen at per environment', async () => {