-
Notifications
You must be signed in to change notification settings - Fork 6
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
Skipping error checks for json.Encoder.Encode
or json.MarshalIndent
is not safe
#14
Comments
(*encoding/json.Encoder).Encode
is not safejson.Encoder.Encode
or json.MarshalIndent
is not safe
@scop I guess, you are right. I started with |
I just looked again at the While it is true, that |
https://cs.opensource.google/go/go/+/refs/tags/go1.17.6:src/encoding/json/scanner.go;l=181;drc=refs%2Ftags%2Fgo1.17.6 is arguably a (pathological) case where scanning the Ignoring that, I guess the call on this boils down to how much one is ready to rely on the internals of the function in question, and that it won't start to actually return errors -- changes in this area aren't necessarily breaking ones and could conceivably occur within Go 1.x series. Then again, I suppose the same could be said about treating any JSON marshalling operations as safe... but it's good that this part of the linter's functionality is user controllable. And IMHO it's good that suggesting omitting error handling is off by default in golangci-lint, even though it's enabled by default in plain errchkjson. |
json.Encoder.Encode
can return an error due to a number of reasons unrelated to the argument's general JSON marshal safety:The same applies to
json.MarshalIndent
:I think errchkjson should not encourage skipping error checks for these functions at all.
(Haven't thought through if there are other messages in errchkjson that should be adjusted due to these considerations, but I suspect there might be some.)
The text was updated successfully, but these errors were encountered: