IntersectMBO / IntersectMBO/cardano-ledger
Confusing DecoderErrorSizeMismatch error message / flipped arguments
- Dominant language
- Haskell
- Stars
- 295
- Forks
- 179
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 29
Description
In `libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/Decoder.hs`, `decodeRecordNamedT` calls `matchSize` with arguments that appear to be swapped:
```haskell
decodeRecordNamedT name getRecordSize decoder =
decodeListLikeT name decoder $ \result n ->
lift $ matchSize ("Record " <> name) n (getRecordSize result)
```
matchSize has the signature:
```haskell
matchSize :: Text.Text -> Int -> Int -> Decoder s ()
matchSize lbl requestedSize actualSize = ...
```
In `decodeListLikeT`, `n` is the list length decoded from the CBOR wire data (the actual/found size). `getRecordSize` result is the expected/requested size. So the call passes n (actual) as `requestedSize` and `getRecordSize` result (expected) as `actualSize` = flipped to the parameter semantics.
The equality check itself is symmetric so mismatches are still caught, but the resulting `DecoderErrorSizeMismatch` error message will label the two values backwards, making debugging confusing.
Suggested fix: swap the arguments:
```haskell
lift $ matchSize ("Record " <> name) (getRecordSize result) n
```
And/or consider labeling the fields in `DecoderErrorSizeMismatch`
Contributor guide
Research direction
Open libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/Decoder.hs and inspect decodeRecordNamedT alongside matchSize. Correct the argument order so expected and decoded record sizes match their parameter semantics, then run the relevant decoder tests and confirm mismatches report the two sizes correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100