Accept full JSON number literals in the internal JSON parser#109
Open
CharlonTank wants to merge 1 commit into
Open
Accept full JSON number literals in the internal JSON parser#109CharlonTank wants to merge 1 commit into
CharlonTank wants to merge 1 commit into
Conversation
The parser only accepted non negative integers, which is all elm.json needs, but lamdera live also uses it (through Json.Decode.value) to relay RPC response envelopes. Any response containing a fractional or negative number failed with 'rpc response decoding failed' even though the backend produced valid JSON. Deployed apps were unaffected, so the same endpoint worked in production and broke only in local dev. Plain integers still parse to the existing Int constructor, so every typed decoder used for elm.json behaves exactly as before. Numbers with a minus sign, a fraction or an exponent now parse to a new Number Scientific constructor, which Json.Decode.value re-encodes through the already existing Json.Encode.Number. Repro: https://github.com/CharlonTank/lamdera-rpc-nofloats-sscce Fixes lamdera#108
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #108
Problem
lamdera liverelays RPC response envelopes through the compiler's internal JSON parser (extra/Lamdera/CLI/Live.hs,D.field "v" D.value). That parser was written forelm.jsonfiles and only accepts non negative integers: fractions and exponents raise the dedicatedNoFloatsparse error, and a leading minus is not recognized at all. As a result, any RPC response containing42.5or-5anywhere fails withrpc response decoding failed for {...}in local dev, while the same endpoint works fine in production.Minimal repro (integer endpoint works, float and negative endpoints fail): https://github.com/CharlonTank/lamdera-rpc-nofloats-sscce
Fix
Teach
compiler/src/Json/Decode.hsfull JSON number literals:Intconstructor, byte for byte the same accumulation as before, so every typed decoder used forelm.json(versions, dependency constraints, ...) behaves exactly as it did.Number Data.ScientificAST constructor.Json.Decode.valuere-encodes it through the already existingJson.Encode.Number Scientific, so the value round-trips exactly.NoLeadingZerosrule is preserved. Malformed tails like1.or2estill error (reusingNoFloatsas the error constructor, which avoids touching the public error type).int,bool,string, ...) have wildcard fallbacks, so a fractional number where an int is expected now produces the regular "expecting an INT" decode error instead of a parse failure. No other behavior changes.Verification
{"value":42},{"value":42.5},{"value":-5}).lamdera makestill compiles both the SSCCE app and a production app with roughly 500 modules and a largeelm.json, confirmingelm.jsonparsing is unchanged.