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: decoding error #43156

Closed
gohryt opened this issue Dec 12, 2020 · 2 comments
Closed

encoding/json: decoding error #43156

gohryt opened this issue Dec 12, 2020 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@gohryt
Copy link

gohryt commented Dec 12, 2020

What version of Go are you using (go version)?

1.15.6

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/gohryt/.cache/go-build"
GOENV="/home/gohryt/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/gohryt/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/gohryt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib64/golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib64/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="x86_64-solus-linux-gcc"
CXX="x86_64-solus-linux-g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build993101165=/tmp/go-build -gno-record-gcc-switches"

What did you do?

PropertiesStruct struct {
BasedOn string
Api float64
ApiId string
ClientId string
ClientSecret string
DefaultPage string
}

func (p PropertiesStruct) ...() {
...
gjson.FromFile(Core.Application.Directory+"/Properties", &p, &Standard)
...
}

func FromFile(filePath string, target interface{}, errorChannel *chan error) {
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0777)
if err != nil {
*errorChannel <- err
}
data, err := ioutil.ReadAll(file)
if err != nil {
*errorChannel <- err
}
err = json.Unmarshal(data, target)
if err != nil {
*errorChannel <- err
}
file.Close()
}

What did you expect to see?

json decoded to caller (p)

What did you see instead?

When json.Unmarshal works it freezes but no crash.
I tried to set `json:"Smthng"` tags for struct members with same names as struct member names and it was as at start.
Then i changed json tag for apiid and clientid to `json:"ApiIP"` and `json:"ClientID"` and it decodes json and works "correctly".

@dsnet
Copy link
Member

dsnet commented Dec 12, 2020

Hi, this report insufficiently detailed for us to triage. Can you provide a runnable snippet?

@dsnet dsnet added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 12, 2020
@dsnet dsnet changed the title Json decoding error encoding/json: decoding error Dec 12, 2020
@AlexRouSg
Copy link
Contributor

AlexRouSg commented Dec 13, 2020

Just a hunch but ...

if err != nil {
*errorChannel <- err
}

I think you meant to do

if err != nil {
*errorChannel <- err
return
}

Also why are you using a pointer to a chan?

@gohryt gohryt closed this as completed Jan 7, 2021
@golang golang locked and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants