Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

fix(pg): treat a stray Foreign as an error-null, not a value-null

public

fix(pg): treat a stray Foreign as an error-null, not a value-null

feel-pg can never build a `Foreign` (its input is JSONB, not host objects), so the
`value_to_json` arm is purely for exhaustiveness — but it should signal an error
rather than a benign absence. Group it with `Value::Error` so the intent is an
error-null, matching the evaluator's "unexpected value -> error-null" rule (ADR-21).
`contains_error` stays Foreign-insensitive on purpose: in feel-py/feel-wasm a
`Foreign` result is a legitimate pass-through and must not raise under strict mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changeset995047acb97305605f2f3d31fe2da3102e7d7f39
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents60e90496826b
Children
Pushlog
by timo via ssh

modified DECISIONS.md +2 −1

@@ -563,7 +563,8 @@
563563
   pinned by a size test), and the `forced` checks fall through with a single predicted
564564
   branch when no `Foreign` exists. ADR-1 holds — the trait is std-only, like the
565565
   `FeelRegex` seam (ADR-16) — and feel-pg, which never builds a `Foreign`, gains one
566
-  defensive, unreachable match arm. Cyclic graphs need **no** engine guard: a finite
566
+  defensive, unreachable match arm that treats a stray `Foreign` as an *error-null*
567
+  (the evaluator's "unexpected value -> error-null" rule), not a silent value-null. Cyclic graphs need **no** engine guard: a finite
567568
   expression navigates a finite path, and output passes through rather than re-walking,
568569
   so the `js_to_value`/`py_to_value` guards added under ADR-20 are removed. The single
569570
   residual is structurally comparing two *distinct* cyclic foreign graphs, bounded by

modified crates/feel-pg/src/lib.rs +9 −6

@@ -127,12 +127,15 @@
127127
         | Value::DaysTimeDuration(_) => feel_core::temporal::to_iso(value)
128128
             .map(serde_json::Value::String)
129129
             .unwrap_or(serde_json::Value::Null),
130
-        // Lenient: an error-null serialises like a plain null. Strict callers
131
-        // check `Value::contains_error` before reaching here.
132
-        Value::Null | Value::Error => serde_json::Value::Null,
133
-        // feel-pg never builds a `Foreign` (its input is JSONB, not host objects),
134
-        // so this is unreachable; map defensively to null rather than panic (ADR-21).
135
-        Value::Foreign(_) => serde_json::Value::Null,
130
+        // A value-null serialises as a plain JSON null.
131
+        Value::Null => serde_json::Value::Null,
132
+        // An error-null serialises as JSON null too at the lenient boundary (strict
133
+        // callers check `Value::contains_error` upstream). A `Foreign` cannot
134
+        // legitimately reach feel-pg — its input is JSONB, not host objects — so a
135
+        // stray one is grouped here as an *error-null*, mirroring the evaluator's
136
+        // "unexpected value -> error-null" rule, rather than a silent value-null
137
+        // (ADR-21).
138
+        Value::Error | Value::Foreign(_) => serde_json::Value::Null,
136139
     }
137140
 }
138141