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: mapEncoder.encode should not use MarshalerError #29753

Open
ianlancetaylor opened this issue Jan 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@ianlancetaylor
Copy link
Contributor

commented Jan 15, 2019

As of CL 20356, if there is an error in encoding/json.mapEncoder.encode, it returns an error of type MarshalerError. But the message printed by MarshalerError's Error method refers to MarshalJSON, and that method was never called. Every other use of MarshalerError is in the context of a call to MarshalJSON or MarshalText. I think that mapEncoder.encode should use a different error type; I note that stringEncoder simply calls fmt.Errorf.

Also we should probably change MarshalerError's message to refer to MarshalText as well as MarshalJSON.

CC @augustoroman

@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Jan 15, 2019

@augustoroman

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2019

Would it violate the compatibility guarantee to change the error type from MarshalerError to a fmt.Errorf? Perhaps only updating the MarshalerError's message would be sufficient?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor Author

commented Jan 15, 2019

This is permitted by the Go 1 compatibility guarantee. We shouldn't change it if we think that people are relying the returned type, but that doesn't seem particularly likely to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.