IntersectMBO / IntersectMBO/cardano-ledger

Confusing DecoderErrorSizeMismatch error message / flipped arguments

Open Beginner friendly
#5,886 0 comments 0 reactions 0 assignees View on GitHub
:cake: good first issue :credit_card: technical-debt
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.