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

encoding/json: no field information is shown when decoding a map fails #67210

Open
zhiqiangxu opened this issue May 6, 2024 · 5 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zhiqiangxu
Copy link
Contributor

zhiqiangxu commented May 6, 2024

Go version

go version go1.22.0 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/alanxu/Library/Caches/go-build'
GOENV='/Users/alanxu/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/alanxu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/alanxu/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/alanxu/Desktop/github/optimism/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/bd/h02c_p7d6zq0t4tsxr3lkrt00000gn/T/go-build3885504692=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I'm decoding a map with many fields, but the error I got is:

json: cannot unmarshal hex string without 0x prefix into Go value of type common.Address

There's no information about which field is causing the error.

What did you see happen?

The error information when decoding map is vague, it doesn't indicate which field is causing the error.

What did you expect to see?

I expect to see which field(the specific key or value) is causing the error.

@zhiqiangxu zhiqiangxu changed the title encoding/json: no field information is shown when decoding an map encoding/json: no field information is shown when decoding a map May 6, 2024
@zhiqiangxu zhiqiangxu changed the title encoding/json: no field information is shown when decoding a map encoding/json: no field information is shown when decoding a map fails May 6, 2024
@cherrymui
Copy link
Member

Could you share a specific example that reproduce the issue? Thanks.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 6, 2024
@zhiqiangxu
Copy link
Contributor Author

zhiqiangxu commented May 7, 2024

Could you share a specific example that reproduce the issue? Thanks.

Here is the minimal program to reproduce.

It reports: json: cannot unmarshal hex string without 0x prefix into Go value of type common.Hash

(In my actual case, the map has a lot of fields.)

@zhiqiangxu
Copy link
Contributor Author

zhiqiangxu commented May 9, 2024

@cherrymui maybe the WaitingForInfo label can be removed?

@cherrymui cherrymui added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels May 9, 2024
@cherrymui cherrymui added this to the Backlog milestone May 9, 2024
@cherrymui
Copy link
Member

Thanks.

cc @rsc @dsnet @bradfitz @mvdan

@dsnet
Copy link
Member

dsnet commented May 9, 2024

The v2 JSON discussion (#63397) includes a JSONPointer field in jsontext.SyntacticError and json.SemanticError. Such a field would be used to store a JSON pointer (RFC 6901), that would describe exactly where an error occurred.

Support for populating this is planned, but not currently implemented in the prototype implementation at https://github.com/go-json-experiment/json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants