Skip to content

fix: return decode errors for padded fields - #76

Merged
jszwec merged 1 commit into
jszwec:masterfrom
bensynapse:fix-short-row-error
Oct 24, 2026
Merged

jszwec merged 1 commit into
jszwec:masterfrom
bensynapse:fix-short-row-error

Conversation

@bensynapse

Copy link
Copy Markdown
Contributor

I run Live Tennis API.

With AlignRecord enabled, decoding a short row can panic when csv.Reader.FieldPos looks up a field added during padding. For example, A,B\na\n decoded into a struct with an integer B field panics instead of returning an error.

Keep the original field count and return DecodeError without a source position for padded fields. Errors in real fields keep their positions. The tests cover numeric and boolean fields, explicit and reordered headers, custom errors, extra columns and reading further rows with ReuseRecord.

Nine new cases panic before this fix. All fifteen new cases and the full suite pass with go test -race -v ./... on Go 1.21.13, 1.22.12 and 1.23.4. Build and vet pass on Go 1.23.4.

Keep the original record length when AlignRecord adds empty fields. Report
DecodeError without querying FieldPos for fields absent from the input.
@jszwec

jszwec commented Oct 24, 2026

Copy link
Copy Markdown
Owner

nice catch, thanks!

@jszwec
jszwec merged commit 9165144 into jszwec:master Oct 24, 2026
5 checks passed
@jszwec jszwec added the bug label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants