-
-
Save mseddon/0dc4cab531ed200b2e56f0247d9cb3f1 to your computer and use it in GitHub Desktop.
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
(defmacro with-sexpr-errors | |
"Takes the metadata from evaluating expr. if metadata is present, wraps | |
the source line information from this expression in a CompilerException, so the source is correctly | |
recovered in the error report." | |
[expr body] | |
`(let [md# (meta ~expr)] | |
(if md# | |
(try | |
~body | |
(catch clojure.lang.Compiler$CompilerException e# | |
; don't re-wrap a compiler exception | |
(throw e#)) | |
(catch Throwable e# | |
(throw (clojure.lang.Compiler$CompilerException. | |
~*file* | |
(:line md#) | |
(:column md#) | |
e#)))) | |
~body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment