Compiler.load() reports wrong exception phase

Description

Compiler.load() throws CompilerException without setting the phase, which then uses default, which is :compile-syntax-check.

Given a file that, on load, will trigger an execution error:

1 2 3 4 $ cat a/lo.clj (ns lo) (defn trigger [] (/ 1 0)) (trigger)

Loading it will report as a compile exception, even though it's not a compile error (also, the location is wrong as it points to the invoke at the end):

1 2 3 4 5 $ clj -Sdeps '{:paths ["a"]}' Clojure 1.10.1 user=> (require 'lo) Syntax error (ArithmeticException) compiling at (lo.clj:3:1). Divide by zero

This case occurs particularly in Cursive, which wraps the eval'ed expression in a form that is loaded by Cursive, so all evals from within a source file have this issue.

Cause: The cause of this is in Compiler.load() - that code catches Throwable and wraps it in a CompilerException, using the original constructor which has a default phase in it.

Proposed: If the exception is a CompilerException or another exception with a phase, just pass it through. Otherwise, create a CompilerException in execution phase instead.

Patch: clj-2529.patch

After, the error is execution, not compilation and it points to the line that actually caused the exception:

1 2 3 user=> (require 'lo) Execution error (ArithmeticException) at lo/trigger (lo.clj:2). Divide by zero

Environment

None

Status

Assignee

Unassigned

Reporter

Alex Miller

Labels

Approval

Vetted

Patch

Code

Affects versions

Release 1.10

Priority

Major
Configure