-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from rymndhng/add-pretty-app-frame
Add custom app frames with bolded clojure frame font
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
(ns demo-app-frames | ||
"This namespace demonstrates how customizing io.aviso.exception/*app-frames* | ||
helps highlight application logic in stacktraces | ||
The `comment` block at end of file demonstrates this feature. | ||
" | ||
(:require [io.aviso.repl :as repl])) | ||
(repl/install-pretty-exceptions) | ||
|
||
;; -- provided.* namespaces are libraries we're consuming --------------------- | ||
(ns provided.db | ||
(:import (java.sql SQLException))) | ||
(defn jdbc-update | ||
[] | ||
(throw (SQLException. "Database failure" "ABC" 123))) | ||
|
||
|
||
(ns provided.worker) | ||
(defprotocol Worker | ||
(do-work [this])) | ||
|
||
|
||
(ns provided.db-worker) | ||
(defn make-jdbc-update-worker | ||
[] | ||
(reify | ||
provided.worker/Worker | ||
(provided.worker/do-work [this] (provided.db/jdbc-update)))) | ||
|
||
;; -- my-app are namespaces belonging to our application ---------------------- | ||
(ns my-app.db) | ||
(defn update-row | ||
[] | ||
(try | ||
(-> (provided.db-worker/make-jdbc-update-worker) provided.worker/do-work) | ||
(catch Throwable e | ||
(throw (RuntimeException. "Failure updating row" e))))) | ||
|
||
|
||
(ns my-app.handler) | ||
(defn make-exception | ||
"Creates a sample exception used to test the exception formatting logic." | ||
[] | ||
(try | ||
(my-app.db/update-row) | ||
(catch Throwable e | ||
;; Return it, not rethrow it. | ||
(RuntimeException. "Request handling exception" e)))) | ||
|
||
(defn make-ex-info | ||
"" | ||
[] | ||
(try | ||
(throw (make-exception)) | ||
(catch Throwable t | ||
;; Return it, not rethrow it. | ||
(ex-info "Exception in make-ex-info." | ||
{:function 'make-exception} | ||
t)))) | ||
|
||
|
||
(ns my-app.handler-test | ||
(:require [clojure.test :refer [report]])) | ||
|
||
(defn test-failure | ||
[] | ||
(report {:type :error :expected nil :actual (my-app.handler/make-ex-info)})) | ||
|
||
|
||
(comment | ||
;; Run these commands in a REPL | ||
(require '[demo-appframes] :reload) | ||
|
||
;; Should show no app-frames highlighted | ||
(alter-var-root #'io.aviso.exception/*app-frame-names* (constantly [])) | ||
(my-app.handler-test/test-failure) | ||
|
||
;; Should show app-frames (beginning with my-app) highlighted | ||
(alter-var-root #'io.aviso.exception/*app-frame-names* (constantly [#"my-app.*"])) | ||
(my-app.handler-test/test-failure) | ||
|
||
) |