Skip to content

Commit 9944ea6

Browse files
committed
feat: add fail safe for override evaluation
1 parent aabb2ae commit 9944ea6

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,12 @@ function evaluateCondition(
166166
return contextValue === castedValue ? "matched" : "not_matched";
167167

168168
case "in":
169-
return Array.isArray(castedValue) && castedValue.includes(contextValue)
170-
? "matched"
171-
: "not_matched";
169+
if (!Array.isArray(castedValue)) return "unknown";
170+
return castedValue.includes(contextValue) ? "matched" : "not_matched";
172171

173172
case "not_in":
174-
return Array.isArray(castedValue) && !castedValue.includes(contextValue)
175-
? "matched"
176-
: "not_matched";
173+
if (!Array.isArray(castedValue)) return "unknown";
174+
return !castedValue.includes(contextValue) ? "matched" : "not_matched";
177175

178176
case "less_than":
179177
if (typeof contextValue === "number" && typeof castedValue === "number") {
@@ -768,14 +766,19 @@ function _createReplaneClient(
768766
if (isWatcherClosed) {
769767
throw new Error("Config value watcher is closed");
770768
}
771-
return evaluateOverrides<T>(
772-
currentConfig.value,
773-
currentConfig.overrides,
774-
{
775-
...options.context,
776-
...context,
777-
}
778-
);
769+
try {
770+
return evaluateOverrides<T>(
771+
currentConfig.value,
772+
currentConfig.overrides,
773+
{
774+
...options.context,
775+
...context,
776+
}
777+
);
778+
} catch (err) {
779+
options.logger.error(`ReplaneConfigWatcherWorker error: ${err}`);
780+
return currentConfig.value;
781+
}
779782
},
780783
close() {
781784
if (isWatcherClosed) return;

0 commit comments

Comments
 (0)