diff options
author | Vincent Ambo <tazjin@google.com> | 2019-10-28T21·38+0100 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2019-10-29T18·16+0100 |
commit | 904c3dade00881c6872dc633a135e12bdfe7e76b (patch) | |
tree | c94c47789e6007f4ac340861dc75158a2ea3af4d /tools | |
parent | 3a7c964a22ac0d7805cbe2d0a5f42f030ee68c19 (diff) |
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.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nixery/server/logs.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/tools/nixery/server/logs.go b/tools/nixery/server/logs.go index cc218c69d265..7077b2b208fe 100644 --- a/tools/nixery/server/logs.go +++ b/tools/nixery/server/logs.go @@ -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) { |