-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imitate clojure.main Error Reporting
Fixes #1004
- Loading branch information
Showing
8 changed files
with
166 additions
and
52 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
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
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
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,35 @@ | ||
(ns ^:no-doc planck.from.clojure.main | ||
(:require | ||
[planck.core :refer [requiring-resolve with-open spit]] | ||
[planck.io :as io :refer [temp-file]] | ||
[cljs.repl])) | ||
|
||
;; Copied and revised for use in Planck | ||
(defn report-error | ||
"Create and output an exception report for a Throwable to target. | ||
Options: | ||
:target - \"file\" (default), \"stderr\", \"none\" | ||
If file is specified but cannot be written, falls back to stderr." | ||
[t & {:keys [target] | ||
:or {target "file"} :as opts}] | ||
(when-not (= target "none") | ||
(let [trace (cljs.repl/Error->map t) | ||
triage (cljs.repl/ex-triage trace) | ||
message (cljs.repl/ex-str triage) | ||
report (array-map | ||
:planck.repl/message message | ||
:planck.repl/triage triage | ||
:planck.repl/trace trace) | ||
report-str (with-out-str | ||
(binding [*print-namespace-maps* false] | ||
((requiring-resolve 'clojure.pprint/pprint) report))) | ||
err-path (when (= target "file") | ||
(try | ||
(let [f (temp-file)] | ||
(spit f report-str) | ||
(:path f)) | ||
(catch :default _)))] ;; ignore, fallback to stderr | ||
(binding [*print-fn* *print-err-fn*] | ||
(if err-path | ||
(println (str message \newline "Full report at:" \newline err-path)) | ||
(println (str report-str \newline message))))))) |
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