Repository navigation
Description
Summary
When custom operators (fractional, sem_ver, starts_with, ends_with) receive invalid input, the return value varies across SDK implementations. In JSONLogic, null/nil and false have different semantics — null typically causes a fallback to the default variant, while false takes the false branch of a conditional. This means the same malformed targeting rule produces different evaluation outcomes depending on which SDK evaluates it.
The Problem
sem_ver — null vs false on error
The most impactful inconsistency. When sem_ver fails to parse a version or receives an unknown operator:
| SDK | Error return | JSONLogic effect |
|---|---|---|
| Go | false |
Takes the false branch |
| Java | null |
Triggers default variant fallback |
| JS/TS | false |
Takes the false branch |
| C#/.NET | false |
Takes the false branch |
| Python | None |
Triggers default variant fallback |
| Rust | Null |
Triggers default variant fallback |
In a rule like {"if": [{"sem_ver": [...]}, "variant-a", "variant-b"]}, a parse failure returns "variant-b" in Go/JS/.NET but triggers the default variant in Java/Python/Rust.
starts_with / ends_with — Go internal inconsistency
Go returns different values for two operators that share the same input validation:
| Operator | Go error return |
|---|---|
starts_with |
nil |
ends_with |
false |
All other SDKs are internally consistent for these two operators (Java returns null for both; JS/.NET return false for both; Python returns None or False depending on the error type).
fractional — divergent "no bucket matched" behavior
When a user's hash doesn't fall into any bucket range (e.g., due to weight misconfiguration):
| SDK | No-match return | Effect |
|---|---|---|
| Go | "" (empty string) |
Variant lookup fails → error |
| Java | throws JsonLogicEvaluationException |
Evaluation error propagated |
| JS/TS | null |
Default variant fallback |
| C#/.NET | "" (empty string) |
Variant lookup fails → error |
| Python | None |
Default variant fallback |
| Rust | Value::Null |
Default variant fallback |
Three different behaviors: empty string (Go/.NET), exception (Java), or null fallback (JS/Python/Rust).
Full Error Return Matrix
| Operator | Error Type | Go | Java | JS/TS | .NET | Python | Rust |
|---|---|---|---|---|---|---|---|
fractional |
Parse/input error | nil |
null |
null |
null |
None |
Null |
fractional |
No bucket matched | "" |
throws | null |
"" |
None |
Null |
sem_ver |
Any error | false |
null |
false |
false |
None |
Null |
starts_with |
Any error | nil |
null |
false |
false |
None/False |
N/A (built-in) |
ends_with |
Any error | false |
null |
false |
false |
None/False |
N/A (built-in) |
Suggested Fix
- Standardize error returns per operator and document the expected behavior in the spec:
fractionalerrors →null(triggers default variant fallback)sem_vererrors → decide betweenfalseornulland apply consistentlystarts_with/ends_witherrors → decide betweenfalseornulland apply consistently
- Fix Go's
starts_with/ends_withinconsistency — both should return the same value on error. - Fix
fractionalno-bucket-match — standardize tonull(fallback to default) rather than empty string or exception. - Add Gherkin test cases that exercise error paths (wrong arg count, invalid types, unparseable versions) and assert the expected return value.
Related: #1770
Activity
[-]Custom operator error return values are inconsistent across SDK implementations[/-][+][BUG] Custom operator error return values are inconsistent across SDK implementations[/+]test(operators): add error return scenarios for sem_ver and fractiona…
test(operators): add error return scenarios for sem_ver and fractiona…
test(operators): add follow-up error scenarios for operator null-retu…
test(operators): add error return scenarios for sem_ver and fractiona…
test(operators): add follow-up error scenarios for operator null-retu…
test(operators): add follow-up error scenarios for operator null-retu…
test(operators): add follow-up error scenarios for operator null-retu…
test(operators): add follow-up error scenarios for operator null-retu…
toddbaert commentedon Apr 14, 2026
Closing in favor of per-repo testbed v3.6.0 upgrade issues, which collectively cover all the edge cases identified here:
fix(core): fall back to the default variant on malformed computed res…
fix(core): fall back to the default variant on malformed computed res…
feat: add resolve operator support (#2127)