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

Comments

@Gohryt
Copy link

@Gohryt 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 dsnet commented Dec 12, 2020

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

@dsnet dsnet changed the title Json decoding error encoding/json: decoding error Dec 12, 2020
@AlexRouSg
Copy link
Contributor

@AlexRouSg 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 Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants