Skip to content

Commit

Permalink
reporter/report-error: allow reporting a message with extra data (#69)
Browse files Browse the repository at this point in the history
It seems that since [this
change](c3fa4f4#diff-1d086718b79e44223815f06018dd5b132dbd6a516a4437241c8a76a3aedcd7dcL83-R85)
we lost the ability to provide a message plus some extra data. Allowed
the fn to accept the `:extra` params along the hash map with the
`:message` field.
  • Loading branch information
jeremyvdw authored Apr 16, 2024
1 parent 4749913 commit 8e039bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/spootnik/reporter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@

([error extra]
(log/error error)
(-> (capture! (if (instance? Exception error)
{:extra extra
:throwable error}
{:message error}))
(d/catch Throwable
(fn [e]
(log/error e "Sentry failure")))
(try
(catch Throwable e
(log/error e "Sentry failure"))))))
(let [payload (cond-> {:extra extra}
(instance? Exception error) (assoc :throwable error)
(:message error) (assoc :message (:message error)))]
(-> (capture! payload)
(d/catch Throwable
(fn [e]
(log/error e "Sentry failure")))
(try
(catch Throwable e
(log/error e "Sentry failure")))))))
19 changes: 19 additions & 0 deletions test/spootnik/reporter/reporter_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns spootnik.reporter.reporter-test
(:require
[clojure.test :refer [deftest is testing]]
[spootnik.reporter :as sut]))

(deftest report-error-test
(with-redefs [sut/capture! identity]
(testing "with message"
(is (= {:message "error message" :extra {:foo "bar"}}
(sut/report-error {:message "error message"}
{:foo "bar"}))))

(testing "with exception"
(let [e (ex-info "Exception" {:some :more-data}
(ex-info "Root exception" {:some :data}))]
(is (= {:throwable e :extra {:foo "bar"}}
(sut/report-error e
{:foo "bar"})))))))

0 comments on commit 8e039bb

Please sign in to comment.