Skip to content

Commit 25dd97c

Browse files
committed
chore: throw-error-if-metadata-missing
1 parent c144f7a commit 25dd97c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sdk/models.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ export class Flags {
120120
for (const flag of Object.values(evaluationResult.flags)) {
121121
const flagsmithId = flag.metadata?.flagsmithId;
122122
if (!flagsmithId) {
123-
continue;
123+
throw new Error(
124+
`FlagResult metadata.flagsmithId is missing for feature "${flag.name}". ` +
125+
`This indicates a bug in the SDK, please report it.`
126+
);
124127
}
125128

126129
flags[flag.name] = new Flag({

tests/sdk/flagsmith.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,23 @@ test('get_user_agent_extracts_version_from_package_json', async () => {
519519

520520
expect(userAgent).toBe(`flagsmith-nodejs-sdk/${packageJson.version}`);
521521
});
522+
523+
test('Flags.fromEvaluationResult throws error when metadata.flagsmithId is missing', () => {
524+
const evaluationResult = {
525+
flags: {
526+
test_feature: {
527+
enabled: true,
528+
name: 'test_feature',
529+
value: 'test_value',
530+
reason: 'DEFAULT',
531+
metadata: {}
532+
}
533+
},
534+
segments: []
535+
};
536+
537+
expect(() => Flags.fromEvaluationResult(evaluationResult as any)).toThrow(
538+
'FlagResult metadata.flagsmithId is missing for feature "test_feature". ' +
539+
'This indicates a bug in the SDK, please report it.'
540+
);
541+
});

0 commit comments

Comments
 (0)