Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: return descriptive error instead of io.EOF for empty string#196

Open
Yanhu007 wants to merge 1 commit into
ericlagergren:master from
Yanhu007:fix/unmarshal-empty-string-eof
Open

fix: return descriptive error instead of io.EOF for empty string #196
Yanhu007 wants to merge 1 commit into
ericlagergren:master from
Yanhu007:fix/unmarshal-empty-string-eof

Conversation

@Yanhu007

@Yanhu007 Yanhu007 commented Apr 15, 2026

Copy link
Copy Markdown

Fixes #190

Problem

UnmarshalText([]byte("")) returns a bare io.EOF error:

var d decimal.Big
err := d.UnmarshalText([]byte(""))
// err == io.EOF ← confusing, looks like a Reader was consumed

This is confusing in JSON unmarshaling contexts where io.EOF is typically interpreted as the input stream being exhausted, not as invalid input.

Fix

In scanSign, convert io.EOF to a descriptive error: "decimal: cannot scan empty string".

var d decimal.Big
err := d.UnmarshalText([]byte(""))
// err == "decimal: cannot scan empty string" ← clear

UnmarshalText("") returned a bare io.EOF error which is confusing
because io.EOF typically signals a Reader was already consumed.
Return a descriptive "cannot scan empty string" error instead.
Fixes ericlagergren#190 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Unmarshaling empty string returns io.EOF error and it breaks/stops JSON unmarshaling

1 participant

AltStyle によって変換されたページ (->オリジナル) /