Skip to content

Commit f76cae8

Browse files
authored
fix: incorrect evaluation details code returned for TYPE_MISMATCH (#117)
1 parent e4f1b16 commit f76cae8

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/client/eppo-client-assignment-details.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,49 @@ describe('EppoClient get*AssignmentDetails', () => {
235235
} as IAssignmentDetails<number>);
236236
});
237237

238+
it('should handle type mismatches with graceful failure mode enabled', () => {
239+
const client = new EppoClient(storage);
240+
client.setIsGracefulFailureMode(true);
241+
const result = client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true);
242+
expect(result).toEqual({
243+
variation: true,
244+
action: null,
245+
evaluationDetails: {
246+
environmentName: 'Test',
247+
flagEvaluationCode: 'TYPE_MISMATCH',
248+
flagEvaluationDescription:
249+
'Variation value does not have the correct type. Found INTEGER, but expected BOOLEAN for flag integer-flag',
250+
variationKey: null,
251+
variationValue: null,
252+
banditKey: null,
253+
banditAction: null,
254+
configFetchedAt: expect.any(String),
255+
configPublishedAt: expect.any(String),
256+
matchedRule: null,
257+
matchedAllocation: null,
258+
unmatchedAllocations: [],
259+
unevaluatedAllocations: [
260+
{
261+
key: 'targeted allocation',
262+
allocationEvaluationCode: AllocationEvaluationCode.UNEVALUATED,
263+
orderPosition: 1,
264+
},
265+
{
266+
key: '50/50 split',
267+
allocationEvaluationCode: AllocationEvaluationCode.UNEVALUATED,
268+
orderPosition: 2,
269+
},
270+
],
271+
},
272+
} as IAssignmentDetails<boolean>);
273+
});
274+
275+
it('should throw an error for type mismatches with graceful failure mode disabled', () => {
276+
const client = new EppoClient(storage);
277+
client.setIsGracefulFailureMode(false);
278+
expect(() => client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true)).toThrow();
279+
});
280+
238281
describe('UFC General Test Cases', () => {
239282
const testStart = Date.now();
240283

src/client/eppo-client.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,15 @@ export default class EppoClient {
750750
}
751751

752752
if (!checkTypeMatch(expectedVariationType, flag.variationType)) {
753-
throw new TypeError(
754-
`Variation value does not have the correct type. Found: ${flag.variationType} != ${expectedVariationType} for flag ${flagKey}`,
755-
);
753+
const errorMessage = `Variation value does not have the correct type. Found ${flag.variationType}, but expected ${expectedVariationType} for flag ${flagKey}`;
754+
if (this.isGracefulFailureMode) {
755+
const flagEvaluationDetails = flagEvaluationDetailsBuilder.buildForNoneResult(
756+
'TYPE_MISMATCH',
757+
errorMessage,
758+
);
759+
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
760+
}
761+
throw new TypeError(errorMessage);
756762
}
757763

758764
if (!flag.enabled) {
@@ -780,9 +786,9 @@ export default class EppoClient {
780786

781787
if (result?.variation && !checkValueTypeMatch(expectedVariationType, result.variation.value)) {
782788
const { key: vKey, value: vValue } = result.variation;
783-
const reason = `Expected variation type ${expectedVariationType} does not match for variation '${vKey}' with value ${vValue}`;
789+
const reason = `Variation (${vKey}) is configured for type ${expectedVariationType}, but is set to incompatible value (${vValue})`;
784790
const flagEvaluationDetails = flagEvaluationDetailsBuilder.buildForNoneResult(
785-
'TYPE_MISMATCH',
791+
'ASSIGNMENT_ERROR',
786792
reason,
787793
);
788794
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);

0 commit comments

Comments
 (0)