Skip to content

Commit

Permalink
fix: handle check against non existing projects (#5368)
Browse files Browse the repository at this point in the history
Instead of throwing an error when the project doesn't exist, we say that
the names are valid, because we have nothing to say that they're not.
Presumably there is already something in place to prevent you from
importing into a non-existent project.
  • Loading branch information
thomasheartman authored Nov 20, 2023
1 parent 90d6c7c commit 0ba99a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/lib/features/feature-toggle/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,19 +1168,31 @@ class FeatureToggleService {
projectId: string,
featureNames: string[],
): Promise<FeatureNameCheckResultWithFeaturePattern> {
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 (result.state === 'invalid') {
return { ...result, featureNaming: patternData };
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,
);

return { state: 'valid' };
}

return { state: 'valid' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0ba99a6

Please sign in to comment.