Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Errors by

Some CompilerExceptions, especially ones that are thrown by evaluating the init expression of def forms, only contain the file name, not the file path.

For example, let's say you have a file that looks like:

(ns example.core1)

(def x (throw (ex-info "error!!" {})))

And load the namespace, then you'll see the CompilerException only contains the file name, instead of the file path:

user=> (require 'example.core1)
Execution error (ExceptionInfo) at example.core1/fn (core1.clj:3).
error!!
user=> (ex-data *e)
#:clojure.error{:phase :execution, :line 3, :column 8, :source "core1.clj"}
user=>

This is in contrast to other CompilerExceptions, which do contain the file path in their ex-data. For example, let's say you have another file that looks like:

(ns example.core2)

(no-such-function)

And then:

user=> (require 'example.core2)
Syntax error compiling at (example/core2.clj:3:1).
Unable to resolve symbol: no-such-function in this context
user=> (ex-data *e)
#:clojure.error{:phase :compile-syntax-check, :line 3, :column 1, :source "example/core2.clj"}
user=>

It seems that this difference comes from the fact that a DefExpr is constructed with SOURCE passed, instead of SOURCE_PATH.

It would be nice if CompilerExceptions always contain the file path (as far as possible), since it may be hard to identify the exact location where the exception occurred from only the file name.

1 Answer

0 votes
by

Generally, execution exceptions can occur anywhere (not just in Clojure code) and we rely more on the stack trace to identify locations for those with (pst *e). For things like compilation/macroexpansion checks those are definitely in Clojure code so they're handled differently.

...