Skip to content

Commit 58490cd

Browse files
committed
refactor: align evaluation error terminology
1 parent 0d5bdfb commit 58490cd

9 files changed

Lines changed: 41 additions & 34 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@reflag/flag-evaluation": patch
3+
"@reflag/browser-sdk": patch
4+
"@reflag/node-sdk": patch
5+
---
6+
7+
Use consistent evaluation error terminology internally and clarify the error emitted when flags are evaluated before initial flag state is available.

‎packages/browser-sdk/src/client.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ const CLIENT_NOT_INITIALIZED_EVALUATION_ERROR = {
406406
code: "CLIENT_NOT_INITIALIZED",
407407
field: "",
408408
message:
409-
"ReflagClient was not initialized before this flag was evaluated. Call initialize() before evaluating flags.",
409+
"Flag was evaluated before the initial flag state was available. Await initialize() or wait for SDK loading to complete before evaluating flags.",
410410
} as const;
411411

412-
function withClientInitializationDiagnostic(
412+
function withClientInitializationError(
413413
errors: CheckEvent["evaluationErrors"],
414414
evaluatedBeforeInitialization: boolean,
415415
): CheckEvent["evaluationErrors"] {
@@ -1445,7 +1445,7 @@ export class ReflagClient {
14451445
version: f?.targetingVersion,
14461446
ruleEvaluationResults: f?.ruleEvaluationResults,
14471447
missingContextFields: f?.missingContextFields,
1448-
evaluationErrors: withClientInitializationDiagnostic(
1448+
evaluationErrors: withClientInitializationError(
14491449
f?.evaluationErrors,
14501450
evaluatedBeforeInitialization,
14511451
),
@@ -1464,7 +1464,7 @@ export class ReflagClient {
14641464
version: f?.config?.version,
14651465
ruleEvaluationResults: f?.config?.ruleEvaluationResults,
14661466
missingContextFields: f?.config?.missingContextFields,
1467-
evaluationErrors: withClientInitializationDiagnostic(
1467+
evaluationErrors: withClientInitializationError(
14681468
f?.config?.evaluationErrors,
14691469
evaluatedBeforeInitialization,
14701470
),

‎packages/browser-sdk/src/flag/flags.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export type RawFlag = {
9292
missingContextFields?: string[];
9393

9494
/**
95-
* Non-fatal diagnostics produced while evaluating targeting rules.
95+
* Non-fatal errors produced while evaluating targeting rules.
9696
*/
9797
evaluationErrors?: Array<{
9898
code: string;
@@ -142,7 +142,7 @@ export type RawFlag = {
142142
missingContextFields?: string[];
143143

144144
/**
145-
* Non-fatal diagnostics produced while evaluating targeting rules.
145+
* Non-fatal errors produced while evaluating targeting rules.
146146
*/
147147
evaluationErrors?: RawFlag["evaluationErrors"];
148148
};
@@ -265,7 +265,7 @@ export interface CheckEvent {
265265
missingContextFields?: string[];
266266

267267
/**
268-
* Non-fatal diagnostics produced while evaluating the flag.
268+
* Non-fatal errors produced while evaluating the flag.
269269
*/
270270
evaluationErrors?: RawFlag["evaluationErrors"];
271271
}

‎packages/browser-sdk/test/usage.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const clientNotInitializedError = {
3333
code: "CLIENT_NOT_INITIALIZED",
3434
field: "",
3535
message:
36-
"ReflagClient was not initialized before this flag was evaluated. Call initialize() before evaluating flags.",
36+
"Flag was evaluated before the initial flag state was available. Await initialize() or wait for SDK loading to complete before evaluating flags.",
3737
};
3838

3939
vi.mock("../src/sse");
@@ -456,7 +456,7 @@ describe(`sends "check" events `, () => {
456456
});
457457
});
458458

459-
it("adds diagnostics when flags are evaluated before initialization", () => {
459+
it("adds errors when flags are evaluated before initialization", () => {
460460
const sendCheckEventSpy = vi.spyOn(
461461
FlagsClient.prototype,
462462
"sendCheckEvent",
@@ -485,7 +485,7 @@ describe(`sends "check" events `, () => {
485485
);
486486
});
487487

488-
it("does not add initialization diagnostics to bootstrapped evaluations", () => {
488+
it("does not add initialization errors to bootstrapped evaluations", () => {
489489
const sendCheckEventSpy = vi.spyOn(
490490
FlagsClient.prototype,
491491
"sendCheckEvent",
@@ -508,7 +508,7 @@ describe(`sends "check" events `, () => {
508508
);
509509
});
510510

511-
it(`does not send check events or add initialization diagnostics when offline`, () => {
511+
it(`does not send check events or add initialization errors when offline`, () => {
512512
const sendCheckEventSpy = vi.spyOn(
513513
FlagsClient.prototype,
514514
"sendCheckEvent",

‎packages/flag-evaluation/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ export interface EvaluationParams<T extends RuleValue> {
761761
* @property {boolean[]} ruleEvaluationResults - Array indicating the success or failure of each rule evaluated.
762762
* @property {string} [reason] - Optional field providing additional explanation regarding the evaluation result.
763763
* @property {string[]} [missingContextFields] - Legacy array of context fields that were required but not provided during evaluation.
764-
* @property {EvaluationError[]} [errors] - Non-fatal diagnostics for rules that could not be evaluated.
764+
* @property {EvaluationError[]} [errors] - Non-fatal errors for rules that could not be evaluated.
765765
*/
766766
export interface EvaluationResult<T extends RuleValue> {
767767
flagKey: string;

‎packages/flag-evaluation/test/index.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ describe("evaluate flag targeting integration ", () => {
555555
"%s normalization",
556556
(operator) => {
557557
it.each(["admin", "2", "true", "", '{"level":3}', "[false]"])(
558-
"matches normalized element %j without diagnostics",
558+
"matches normalized element %j without errors",
559559
(value) => {
560560
const rules: Rule<string>[] = [
561561
{
@@ -726,7 +726,7 @@ describe("evaluate flag targeting integration ", () => {
726726
]);
727727
});
728728

729-
it("returns a non-fatal diagnostic for scalar-only operators", () => {
729+
it("returns a non-fatal error for scalar-only operators", () => {
730730
const res = evaluateFlagRules({
731731
flagKey: "role-based-flag",
732732
rules: [
@@ -889,7 +889,7 @@ describe("evaluate flag targeting integration ", () => {
889889
});
890890

891891
describe("invalid scalar operator values", () => {
892-
it("returns diagnostics for invalid numeric context and targeting values", () => {
892+
it("returns errors for invalid numeric context and targeting values", () => {
893893
const rules: Rule<boolean>[] = [
894894
{
895895
value: true,
@@ -928,7 +928,7 @@ describe("evaluate flag targeting integration ", () => {
928928
}
929929
});
930930

931-
it("returns diagnostics for invalid date context and targeting values", () => {
931+
it("returns errors for invalid date context and targeting values", () => {
932932
const rules: Rule<boolean>[] = [
933933
{
934934
value: true,
@@ -965,7 +965,7 @@ describe("evaluate flag targeting integration ", () => {
965965
}
966966
});
967967

968-
it("returns a diagnostic for an invalid relative-date offset", () => {
968+
it("returns an error for an invalid relative-date offset", () => {
969969
const rules: Rule<boolean>[] = [
970970
{
971971
value: true,
@@ -994,7 +994,7 @@ describe("evaluate flag targeting integration ", () => {
994994
]);
995995
});
996996

997-
it("returns a diagnostic for an unknown operator", () => {
997+
it("returns an error for an unknown operator", () => {
998998
const rules: Rule<boolean>[] = [
999999
{
10001000
value: true,

‎packages/node-sdk/src/client.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ const CLIENT_NOT_INITIALIZED_EVALUATION_ERROR = {
9090
code: "CLIENT_NOT_INITIALIZED",
9191
field: "",
9292
message:
93-
"ReflagClient was not initialized before this flag was evaluated. Call initialize() before evaluating flags.",
93+
"Flag was evaluated before the initial flag state was available. Await initialize() or wait for SDK loading to complete before evaluating flags.",
9494
} as const;
9595

96-
function withClientInitializationDiagnostic(
96+
function withClientInitializationError(
9797
errors: FlagEvent["evalErrors"],
9898
evaluatedBeforeInitialization: boolean,
9999
): FlagEvent["evalErrors"] {
@@ -1257,7 +1257,7 @@ export class ReflagClient {
12571257
* @param event.evalContext - The evaluation context of the flag to send.
12581258
* @param event.evalRuleResults - The evaluation rule results of the flag to send.
12591259
* @param event.evalMissingFields - The evaluation missing fields of the flag to send.
1260-
* @param event.evalErrors - The non-fatal evaluation diagnostics of the flag to send.
1260+
* @param event.evalErrors - The non-fatal evaluation errors of the flag to send.
12611261
*
12621262
* @throws An error if the event is invalid.
12631263
*
@@ -1377,11 +1377,11 @@ export class ReflagClient {
13771377
}
13781378

13791379
/**
1380-
* Warns if a flag or config evaluation produced diagnostics.
1380+
* Warns if a flag or config evaluation produced errors.
13811381
*
13821382
* @param flag - The flag to check.
13831383
*/
1384-
private _warnFlagEvaluationDiagnostics(flag: {
1384+
private _warnFlagEvaluationErrors(flag: {
13851385
key: string;
13861386
missingContextFields?: string[];
13871387
evaluationErrors?: EvaluationError[];
@@ -1474,7 +1474,7 @@ export class ReflagClient {
14741474
checkContextWithTracking(options);
14751475

14761476
if (!this.initializationFinished && !this._config.offline) {
1477-
this.logger.error("getFlag(s): ReflagClient is not initialized yet.");
1477+
this.logger.error(CLIENT_NOT_INITIALIZED_EVALUATION_ERROR.message);
14781478
}
14791479

14801480
void this.syncContext(options);
@@ -1589,19 +1589,19 @@ export class ReflagClient {
15891589
: { key: undefined, payload: undefined };
15901590
const evaluatedBeforeInitialization =
15911591
!this.initializationFinished && !this._config.offline;
1592-
const flagEvaluationErrors = withClientInitializationDiagnostic(
1592+
const flagEvaluationErrors = withClientInitializationError(
15931593
flag.evaluationErrors,
15941594
evaluatedBeforeInitialization,
15951595
);
1596-
const configEvaluationErrors = withClientInitializationDiagnostic(
1596+
const configEvaluationErrors = withClientInitializationError(
15971597
config?.evaluationErrors,
15981598
evaluatedBeforeInitialization,
15991599
);
16001600

16011601
return {
16021602
get isEnabled() {
16031603
if (enableTracking && enableChecks) {
1604-
client._warnFlagEvaluationDiagnostics(flag);
1604+
client._warnFlagEvaluationErrors(flag);
16051605

16061606
void client
16071607
.sendFlagEvent({
@@ -1625,7 +1625,7 @@ export class ReflagClient {
16251625
},
16261626
get config() {
16271627
if (enableTracking && enableChecks) {
1628-
client._warnFlagEvaluationDiagnostics({ ...flag, config });
1628+
client._warnFlagEvaluationErrors({ ...flag, config });
16291629

16301630
void client
16311631
.sendFlagEvent({

‎packages/node-sdk/src/types.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export type FlagEvent = {
6565
evalMissingFields?: string[];
6666

6767
/**
68-
* Non-fatal diagnostics produced while evaluating the flag (optional).
68+
* Non-fatal errors produced while evaluating the flag (optional).
6969
**/
7070
evalErrors?: Array<{
7171
code: string;
@@ -106,7 +106,7 @@ export type RawFlagRemoteConfig = {
106106
missingContextFields?: string[];
107107

108108
/**
109-
* Non-fatal diagnostics produced while evaluating targeting rules.
109+
* Non-fatal errors produced while evaluating targeting rules.
110110
*/
111111
evaluationErrors?: EvaluationError[];
112112
};
@@ -147,7 +147,7 @@ export interface RawFlag {
147147
missingContextFields?: string[];
148148

149149
/**
150-
* Non-fatal diagnostics produced while evaluating targeting rules.
150+
* Non-fatal errors produced while evaluating targeting rules.
151151
*/
152152
evaluationErrors?: EvaluationError[];
153153
}

‎packages/node-sdk/test/client.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const clientNotInitializedError = {
4747
code: "CLIENT_NOT_INITIALIZED",
4848
field: "",
4949
message:
50-
"ReflagClient was not initialized before this flag was evaluated. Call initialize() before evaluating flags.",
50+
"Flag was evaluated before the initial flag state was available. Await initialize() or wait for SDK loading to complete before evaluating flags.",
5151
};
5252

5353
vi.mock("../src/rate-limiter", async (importOriginal) => {
@@ -1581,7 +1581,7 @@ describe("ReflagClient", () => {
15811581
});
15821582
});
15831583

1584-
it("sends diagnostics when flags are evaluated before initialization", async () => {
1584+
it("sends errors when flags are evaluated before initialization", async () => {
15851585
const context = {
15861586
company,
15871587
user,
@@ -1609,7 +1609,7 @@ describe("ReflagClient", () => {
16091609
]);
16101610
});
16111611

1612-
it("does not add initialization diagnostics when offline", () => {
1612+
it("does not add initialization errors when offline", () => {
16131613
const offlineClient = new ReflagClient({
16141614
...validOptions,
16151615
offline: true,

0 commit comments

Comments
 (0)