From 52039d614e029aae92928219b9672d40f516996d Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Sun, 13 Jul 2014 14:49:59 -0400 Subject: [PATCH] Checks that the `error` field is really and `error` type. --- hooks/airbrake/airbrake.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hooks/airbrake/airbrake.go b/hooks/airbrake/airbrake.go index f24f00d..d92dc88 100644 --- a/hooks/airbrake/airbrake.go +++ b/hooks/airbrake/airbrake.go @@ -24,11 +24,21 @@ func (hook *AirbrakeHook) Fire(entry *logrus.Entry) error { return nil } - err := airbrake.Notify(entry.Data["error"].(error)) - if err != nil { + err, ok := entry.Data["error"].(error) + if !ok { entry.Logger.WithFields(logrus.Fields{ "source": "airbrake", "endpoint": airbrake.Endpoint, + }).Warn("Exceptions sent to Airbrake must have an `error` key of type `error`") + return nil + } + + airErr := airbrake.Notify(err) + if airErr != nil { + entry.Logger.WithFields(logrus.Fields{ + "source": "airbrake", + "endpoint": airbrake.Endpoint, + "error": airErr, }).Warn("Failed to send error to Airbrake") }