nats-io / nats.go

Golang client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
5.45k stars 686 forks source link

Client logs unmarshal errors #1668

Closed sammy007 closed 2 months ago

sammy007 commented 2 months ago

Observed behavior

nats.go logs unmarshal errors using built in log

nats: Got an error trying to unmarshal: json: cannot unmarshal object into Go struct field

Expected behavior

It should not log itself, return error instead which caller will log the way it prefers.

Server and client version

1.36

Host environment

No response

Steps to reproduce

No response

wallyqs commented 2 months ago

How did you run into this error? Using JetStream in some way?

sammy007 commented 2 months ago

How did you run into this error? Using JetStream in some way?

I am using stream in my app and normal messages as well, currently I am trying to find where the bug in my app is :)

Jarema commented 2 months ago

It would be really helpful to know which API call causes this, and see some snippet.

wallyqs commented 2 months ago

can you share the stream info of the stream?

wallyqs commented 2 months ago

you can also setup your own nats.ErrorHandler to override the default one to try to peek further at the json error

sammy007 commented 2 months ago

Well, it is not a stream. In a json encoded connection Publish where I put a struct which contains [][]*SomeStruct as a field.

The struct is:

type A struct {
        .. SKIPPED ...
    B      [][]*C
}
json: cannot unmarshal object into Go struct field A.B of type []*mypackage.C on connection [193] for subscription on "mySub"

The receiver is:

_, err = s.nec.BindRecvChan("mySub", mySubCh)

Will dig further tomorrow

sammy007 commented 2 months ago
mySubCh chan A
_, err = s.nec.BindRecvChan("mySub", mySubCh)

So this is the issue. No idea why it can't deserialize such structure. The structure is nothing special and serializes correctly.

sammy007 commented 2 months ago

Simlar to #245 it seems, but in my case I am just using normal two dimensional array.

sammy007 commented 2 months ago

Well, should be a separate issue anyway.