-
Notifications
You must be signed in to change notification settings - Fork 55
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
strconv.ParseFloat value out of range (big.Int) #192
Comments
hi @razorbohan The error is from the You can custom driver for parse the json. such as: s := `{
"key": 23707729876828933003792990320594511132013137629744363463325945636682800546201191581706241551352734654762086038344743940857801503840360878427584255703013924373301145683882034301334533678253123777083489887967659929148298684008991665609773532863485728577470710590688325197694460521376123072613857785739366064688074459399408762960887169067851291291611970194076234580897060365318108861340336375060983779163595033605894055218557648363640361256922411962394084268360413547861005069585285713253756167043430574673046032573767256949834558011358364591391964981157578571244295339467926678988648036459748021538498339258036608168313
}`
jsd := config.NewDriver("json", func(blob []byte, v any) (err error) {
jnd := json.NewDecoder(bytes.NewReader(blob))
jnd.UseNumber()
return jnd.Decode(v)
}, config.JSONEncoder)
cfg1 := config.NewEmpty("test1").WithDriver(jsd)
err = cfg1.LoadStrings(config.JSON, s)
assert.NoErr(t, err)
dump.P(cfg1.Data())
// to big.Int
bi := new(big.Int)
_, ok := bi.SetString(cfg1.String("key"), 10)
assert.True(t, ok) Output: === RUN TestIssues_192
PRINT AT github.com/gookit/config/v2_test.TestIssues_192(issues_test.go:632)
map[string]interface {} { #len=1
"key": json.Number("23707729876828933003792990320594511132013137629744363463325945636682800546201191581706241551352734654762086038344743940857801503840360878427584255703013924373301145683882034301334533678253123777083489887967659929148298684008991665609773532863485728577470710590688325197694460521376123072613857785739366064688074459399408762960887169067851291291611970194076234580897060365318108861340336375060983779163595033605894055218557648363640361256922411962394084268360413547861005069585285713253756167043430574673046032573767256949834558011358364591391964981157578571244295339467926678988648036459748021538498339258036608168313"), #len=617
},
--- PASS: TestIssues_192 (0.00s) |
@razorbohan Or do you have other solutions? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System (please complete the following information):
macOS 14.6.1
1.21.6
2.2.5
Describe the bug
The library emits error trying to parse big.Int value:
strconv.ParseFloat: parsing "23707729876828933003792990320594511132013137629744363463325945636682800546201191581706241551352734654762086038344743940857801503840360878427584255703013924373301145683882034301334533678253123777083489887967659929148298684008991665609773532863485728577470710590688325197694460521376123072613857785739366064688074459399408762960887169067851291291611970194076234580897060365318108861340336375060983779163595033605894055218557648363640361256922411962394084268360413547861005069585285713253756167043430574673046032573767256949834558011358364591391964981157578571244295339467926678988648036459748021538498339258036608168313": value out of range
My guess is that it is because the lib is trying to parse it to that type of object:
To Reproduce
Have a json file (configPath) with a big.Int value in any field
Expected behavior
A big.Int variable successfully parsed
The text was updated successfully, but these errors were encountered: