refactor(server): Handle non-error errors safely

This case should not be possible unless something manually constructs
a logrus entry with a non-error value in the log.ErrorKey field, but
it's better to be safe than sorry.
This commit is contained in:
Vincent Ambo 2019-10-28 22:38:27 +01:00 committed by Vincent Ambo
parent 3a7c964a22
commit 904c3dade0

View file

@ -76,11 +76,12 @@ func (f stackdriverFormatter) Format(e *log.Entry) ([]byte, error) {
msg["eventTime"] = &e.Time
msg["severity"] = logSeverity(e.Level)
if err, ok := msg[log.ErrorKey]; ok {
// TODO(tazjin): Cast safely - for now there should be
// no calls to `.WithError` with a nil error, but who
// knows.
msg[log.ErrorKey] = (err.(error)).Error()
if e, ok := msg[log.ErrorKey]; ok {
if err, isError := e.(error); isError {
msg[log.ErrorKey] = err.Error()
} else {
delete(msg, log.ErrorKey)
}
}
if isError(e) {