We're updating the issue view to help you get more done. 

Suppress tracebacks from clojure.core

Description

It would be really nice if we could hide the Java traceback from the compiler when it's not relevant. When there's no Java interop, it's not useful. I can't see any case where we want the tracebacks from the compiler referencing clojure.core.

Here's how a syntax error traceback looks at the moment on trunk:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $ more dodgy-map.clj (defn dodgy-map [] {:1 :2 :3}) $ java -cp target/clojure-1.5.0-master-SNAPSHOT.jar clojure.main dodgy-map.clj Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(/home/wilfred/src/clojure/dodgy-map.clj:2:13) at clojure.lang.Compiler.load(Compiler.java:7070) at clojure.lang.Compiler.loadFile(Compiler.java:7020) at clojure.main$load_script.invoke(main.clj:286) at clojure.main$script_opt.invoke(main.clj:348) at clojure.main$main$fn__6682.invoke(main.clj:432) at clojure.main$main.doInvoke(main.clj:429) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.lang.Var.invoke(Var.java:415) at clojure.lang.AFn.applyToHelper(AFn.java:161) at clojure.lang.Var.applyTo(Var.java:532) at clojure.main.main(main.java:37) Caused by: java.lang.RuntimeException: Map literal must contain an even number of forms at clojure.lang.Util.runtimeException(Util.java:219) at clojure.lang.LispReader$MapReader.invoke(LispReader.java:1090) at clojure.lang.LispReader.readDelimitedList(LispReader.java:1145) at clojure.lang.LispReader$ListReader.invoke(LispReader.java:979) at clojure.lang.LispReader.read(LispReader.java:182) at clojure.lang.Compiler.load(Compiler.java:7058) ... 10 more

With my patch, this is simplified to:

1 2 $ java -cp target/clojure-1.5.0-master-SNAPSHOT.jar clojure.main dodgy-map.clj java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(/home/wilfred/src/clojure/dodgy-map.clj:2:13)

Another example: here's how name errors appear on trunk:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 $ more i-dont-exist.clj (defn no-such-variable [] i-dont-exist) $ java -cp target/clojure-1.5.0-master-SNAPSHOT.jar clojure.main i-dont-exist.clj Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: i-dont-exist in this context, compiling:(/home/wilfred/src/clojure/i-dont-exist.clj:1:1) at clojure.lang.Compiler.analyze(Compiler.java:6380) at clojure.lang.Compiler.analyze(Compiler.java:6322) at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5708) at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5139) at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3751) at clojure.lang.Compiler.analyzeSeq(Compiler.java:6558) at clojure.lang.Compiler.analyze(Compiler.java:6361) at clojure.lang.Compiler.analyzeSeq(Compiler.java:6548) at clojure.lang.Compiler.analyze(Compiler.java:6361) at clojure.lang.Compiler.access$100(Compiler.java:37) at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:529) at clojure.lang.Compiler.analyzeSeq(Compiler.java:6560) at clojure.lang.Compiler.analyze(Compiler.java:6361) at clojure.lang.Compiler.analyze(Compiler.java:6322) at clojure.lang.Compiler.eval(Compiler.java:6623) at clojure.lang.Compiler.load(Compiler.java:7063) at clojure.lang.Compiler.loadFile(Compiler.java:7020) at clojure.main$load_script.invoke(main.clj:286) at clojure.main$script_opt.invoke(main.clj:348) at clojure.main$main$fn__6682.invoke(main.clj:432) at clojure.main$main.doInvoke(main.clj:429) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.lang.Var.invoke(Var.java:415) at clojure.lang.AFn.applyToHelper(AFn.java:161) at clojure.lang.Var.applyTo(Var.java:532) at clojure.main.main(main.java:37) Caused by: java.lang.RuntimeException: Unable to resolve symbol: i-dont-exist in this context at clojure.lang.Util.runtimeException(Util.java:219) at clojure.lang.Compiler.resolveIn(Compiler.java:6874) at clojure.lang.Compiler.resolve(Compiler.java:6818) at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6779) at clojure.lang.Compiler.analyze(Compiler.java:6343) ... 25 more

With patch:

1 2 $ java -cp target/clojure-1.5.0-master-SNAPSHOT.jar clojure.main i-dont-exist.clj java.lang.RuntimeException: Unable to resolve symbol: i-dont-exist in this context, compiling:(/home/wilfred/src/clojure/i-dont-exist.clj:1:1)

I'm not familiar with the compiler internals, but I've attached a tentative patch. Undoubtedly it isn't perfect. For one, it would be nicer to say 'Syntax error' rather than 'java.lang.RuntimeException'. All the tests pass with this change.

Relevant mailing list discussion: https://groups.google.com/forum/?fromgroups=#!searchin/clojure/wilfred/clojure/M5NlEW7HJ_c/joUY6mo6Rd8J

Please let me know what you think. This would make my life easier when developing.

Environment

None

Status

Assignee

Unassigned

Reporter

import

Labels

None

Approval

None

Patch

Code

Priority

Minor