lamdera / lamdera/compiler

lamdera live: RPC responses containing fractional or negative JSON numbers fail with 'rpc response decoding failed'

Open
#108 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
95
Forks
21
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the three endpoints from the linked SSCCE with the provided curl commands. Read extra/Lamdera/CLI/Live.hs around the response envelope decoder and compiler/src/Json/Decode.hs; done means fractional and negative JSON response values decode successfully while integer behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.