Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add error msg to UnmarshalText to make the error clearer #36

Merged
merged 1 commit into from
Jan 4, 2025

Conversation

quagmt
Copy link
Owner

@quagmt quagmt commented Jan 4, 2025

Description

  • Current behavior when unmarshaling empty string into a struct that has a Decimal field is not very clear and can cause confusion. For example:
package main

import (
	"encoding/json"
	"fmt"

	"github.com/quagmt/udecimal"
)

type A struct {
	Amount udecimal.Decimal
}

func main() {
	s := `{"Amount": ""}`
	a := A{}
	err := json.Unmarshal([]byte(s), &a)
	fmt.Println(err)

	// Output:
	// panic: parse empty string
}
  • This PR aims to make the error message clearer, instead of just returning parse empty string

Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.19%. Comparing base (c313c7c) to head (9a587c9).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #36   +/-   ##
=======================================
  Coverage   96.18%   96.19%           
=======================================
  Files           5        5           
  Lines        1889     1892    +3     
=======================================
+ Hits         1817     1820    +3     
  Misses         48       48           
  Partials       24       24           

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

@quagmt quagmt merged commit 751d5a2 into master Jan 4, 2025
9 checks passed
@quagmt quagmt deleted the fix/unmarshal-unclear-error-msg branch January 7, 2025 01:09
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