Skip to content

fix: clear inactive result payload when decoding JSON - #122

Merged
samber merged 1 commit into
samber:masterfrom
jakezwang:fix/result-json-reuse
Sep 22, 2026
Merged

samber merged 1 commit into
samber:masterfrom
jakezwang:fix/result-json-reuse

Conversation

@jakezwang

Copy link
Copy Markdown
Contributor

Reusing a Result when decoding JSON leaves the previous inactive payload behind. After an error becomes a success, Error() still returns the old error; after a success becomes an error, OrEmpty() still returns the old value.

Replace the receiver with Ok or Err after successful decoding so both transitions have the same state as a newly constructed result. Regression tests cover both transitions, an empty object, error precedence, same-state updates, and preserving the receiver when decoding fails.

Validation: make build test passed with Go 1.18.10, 1.26.6, and 1.27.1, including the full race suite. make coverage passed with Go 1.27.1; go vet ./... and golangci-lint 2.13.2 also passed on macOS/arm64.

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.26%. Comparing base (2cbaa86) to head (005f8fb).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
+ Coverage   87.42%   88.26%   +0.83%     
==========================================
  Files          28       28              
  Lines        1774     1772       -2     
==========================================
+ Hits         1551     1564      +13     
+ Misses        217      202      -15     
  Partials        6        6              
Flag Coverage Δ
unittests 88.26% <100.00%> (+0.83%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber

samber commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix.

@samber
samber merged commit a6ebb49 into samber:master Sep 22, 2026
19 of 29 checks passed
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.

2 participants