Skip to content

fix: preserve empty result error messages in JSON - #125

Open
yuefdev wants to merge 1 commit into
samber:masterfrom
yuefdev:fix/result-empty-error-json
Open

yuefdev wants to merge 1 commit into
samber:masterfrom
yuefdev:fix/result-empty-error-json

Conversation

@yuefdev

@yuefdev yuefdev commented Oct 18, 2026 •

Copy link
Copy Markdown

An error with an empty message changes into a successful result after a JSON round trip:

data, _ := json.Marshal(mo.Err[int](errors.New("")))
var result mo.Result[int]
json.Unmarshal(data, &result)
// result.IsOk() == true

Decode the message as a pointer so a present empty string still selects the error branch. This also preserves error precedence when the JSON contains both result and an empty error message.

Both regression cases fail before the fix. go test ./... -count=1, go test -race ./... -count=1, go vet ./..., gofmt and the changed-file diff check pass. The race suite ran on Windows with Clang and cgo enabled.

Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant