Closed
Description
From what I can see, if you have an object that implements both json.Marshaler
and error
, it will always use the error
interface. This is despite the fact that code states that json.Marshaler
should always win here. Consider this (I know it's not perfect, but we have a stack trace in our error that we want logged):
type Error struct {
Message string
Status int
}
func (e Error) Error() string {
return e.Message
}
func (e Error) MarshalJSON() ([]byte, error) {
aux := struct{Message string, Status Int}{Message: e.Message, Status: e.Status}
return json.Marshal(aux)
}
And you were to log it:
err := Error{msg: "Error impl", Status: 200}
logger.Log("msg", err)
The result will always be {"err": "Error impl"}
Metadata
Assignees
Labels
No labels
Activity