Skip to content

Instantly share code, notes, and snippets.

@mseddon
Created December 7, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mseddon/0dc4cab531ed200b2e56f0247d9cb3f1 to your computer and use it in GitHub Desktop.
Save mseddon/0dc4cab531ed200b2e56f0247d9cb3f1 to your computer and use it in GitHub Desktop.
(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