Any lamdera_handleEndpoints response whose JSON contains a fractional number (42.5, 0.1, 1e-3, ...) or a negative number (-5) makes lamdera live reply rpc response decoding failed for {...} instead of the response, even though the backend produced valid JSON. Non negative integer responses work fine. Requests containing such numbers are unaffected (they pass through as raw text); only responses break.
Deployed apps are not affected, which makes this extra confusing: the same endpoint works in production and only breaks on lamdera live.
Minimal repro
Full SSCCE with three endpoints (integer works, float and negative fail): https://github.com/CharlonTank/lamdera-rpc-nofloats-sscce
$ curl -s -X POST http://localhost:8002/_r/int-ok -H "Content-Type: application/json" -d '{}'
{
"value": 42
}
$ curl -s -X POST http://localhost:8002/_r/float-bug -H "Content-Type: application/json" -d '{}'
rpc response decoding failed for {"t":"qr","r":"ead924cf-4a07-408c-bdb1-1fdb3623fa7d","c":200,"ct":"OK","h":{},"v":{"value":42.5}}
$ curl -s -X POST http://localhost:8002/_r/neg-bug -H "Content-Type: application/json" -d '{}'
rpc response decoding failed for {"t":"qr","r":"a98c5f2b-d569-4d96-9bbd-8db287575876","c":200,"ct":"OK","h":{},"v":{"value":-5}}
Note the echoed envelopes: they are valid JSON and carry the correct payloads. The bridge just cannot parse them.
Root cause
extra/Lamdera/CLI/Live.hs (around line 695 on lamdera-next) decodes the browser to server RPC response envelope with the compiler's internal JSON parser:
D.oneOf
[ D.field "i" (D.value & fmap ...)
, D.field "v" (D.value & fmap ...) -- Json.Value re-parsed here
, D.field "vs" (D.string & fmap ...)
]
That parser (compiler/src/Json/Decode.hs) was written for elm.json files and only accepts non negative integers: a . or an exponent raises the dedicated NoFloats parse error, and a leading - is not recognized at all. So the D.value extraction of the v field fails on the first such number anywhere in the response, and Live.hs falls into its Left jsonProblem -> "rpc response decoding failed for ..." branch.
I have a fix that teaches the parser full JSON number literals while keeping plain integers on the existing Int constructor (so all typed decoders used for elm.json behave exactly as before); PR incoming.
Any
lamdera_handleEndpointsresponse whose JSON contains a fractional number (42.5,0.1,1e-3, ...) or a negative number (-5) makeslamdera livereplyrpc response decoding failed for {...}instead of the response, even though the backend produced valid JSON. Non negative integer responses work fine. Requests containing such numbers are unaffected (they pass through as raw text); only responses break.Deployed apps are not affected, which makes this extra confusing: the same endpoint works in production and only breaks on
lamdera live.Minimal repro
Full SSCCE with three endpoints (integer works, float and negative fail): https://github.com/CharlonTank/lamdera-rpc-nofloats-sscce
Note the echoed envelopes: they are valid JSON and carry the correct payloads. The bridge just cannot parse them.
Root cause
extra/Lamdera/CLI/Live.hs(around line 695 onlamdera-next) decodes the browser to server RPC response envelope with the compiler's internal JSON parser:That parser (
compiler/src/Json/Decode.hs) was written forelm.jsonfiles and only accepts non negative integers: a.or an exponent raises the dedicatedNoFloatsparse error, and a leading-is not recognized at all. So theD.valueextraction of thevfield fails on the first such number anywhere in the response, and Live.hs falls into itsLeft jsonProblem -> "rpc response decoding failed for ..."branch.I have a fix that teaches the parser full JSON number literals while keeping plain integers on the existing
Intconstructor (so all typed decoders used forelm.jsonbehave exactly as before); PR incoming.