r/Clojure • • Apr 11 '19

Clojure 1.10.1-beta2 is now available

https://clojure.org/community/devchangelog#_1_10_1_beta2_apr_11_2019
81 Upvotes

17 comments sorted by

15

u/alexdmiller Apr 11 '19 edited Apr 11 '19

Two small bumps - slight change in error reporting in CLJ-2497 and an error phase bug we noticed in CLJ-2499.

  • CLJ-2497 Put error report location on its own line

  • CLJ-2499 Some compiler expr evals report as wrong phase

Please try this release as we do not expect to put much, if anything, else into 1.10.1 before release. The error reporting differences in 1.10.1-beta1 are a significantly different experience though, particularly if using clj as a runner (not REPL), or lein, etc. While a couple people have tried it, we have not heard many experience reports on this aspect and would love to hear more.

39

u/alexdmiller Apr 11 '19 edited Apr 11 '19

To make the error reporting difference more concrete, say you misspell `defn` as `dfn` in a leiningen project.

With Clojure 1.10.0:

$ lein compile
Compiling err.core
Syntax error compiling at (err/core.clj:5:1).
Exception in thread "main" Syntax error compiling at (err/core.clj:5:1).
	at clojure.lang.Compiler.analyze(Compiler.java:6808)
	at clojure.lang.Compiler.analyze(Compiler.java:6745)
	at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3820)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:7108)
	at clojure.lang.Compiler.analyze(Compiler.java:6789)
	at clojure.lang.Compiler.analyze(Compiler.java:6745)
	at clojure.lang.Compiler.compile1(Compiler.java:7725)
	at clojure.lang.Compiler.compile(Compiler.java:7797)
	at clojure.lang.RT.compile(RT.java:415)
	at clojure.lang.RT.load(RT.java:461)
	at clojure.lang.RT.load(RT.java:428)
	at clojure.core$load$fn__6824.invoke(core.clj:6126)
	at clojure.core$load.invokeStatic(core.clj:6125)
	at clojure.core$load.doInvoke(core.clj:6109)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5908)
	at clojure.core$compile$fn__6829.invoke(core.clj:6136)
	at clojure.core$compile.invokeStatic(core.clj:6136)
	at clojure.core$compile.invoke(core.clj:6128)
	at user$eval155$fn__164.invoke(form-init17873960244841819464.clj:1)
	at user$eval155.invokeStatic(form-init17873960244841819464.clj:1)
	at user$eval155.invoke(form-init17873960244841819464.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:7176)
	at clojure.lang.Compiler.eval(Compiler.java:7166)
	at clojure.lang.Compiler.eval(Compiler.java:7166)
	at clojure.lang.Compiler.load(Compiler.java:7635)
	at clojure.lang.Compiler.loadFile(Compiler.java:7573)
	at clojure.main$load_script.invokeStatic(main.clj:452)
	at clojure.main$init_opt.invokeStatic(main.clj:454)
	at clojure.main$init_opt.invoke(main.clj:454)
	at clojure.main$initialize.invokeStatic(main.clj:485)
	at clojure.main$null_opt.invokeStatic(main.clj:519)
	at clojure.main$null_opt.invoke(main.clj:516)
	at clojure.main$main.invokeStatic(main.clj:598)
	at clojure.main$main.doInvoke(main.clj:561)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:705)
	at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve symbol: dfn in this context
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.Compiler.resolveIn(Compiler.java:7413)
	at clojure.lang.Compiler.resolve(Compiler.java:7357)
	at clojure.lang.Compiler.analyzeSymbol(Compiler.java:7318)
	at clojure.lang.Compiler.analyze(Compiler.java:6768)
	... 37 more
Compilation failed: Subprocess failed

With Clojure 1.10.1-beta2:

$ lein compile
Compiling err.core
Syntax error compiling at (err/core.clj:5:1).
Syntax error compiling at (err/core.clj:5:1).
Unable to resolve symbol: dfn in this context

Full report at:
/var/folders/2k/2l7ch1xn7lb5gj86tgp1ygww0000gn/T/clojure-3724210784369662770.edn
Compilation failed: Subprocess failed

The full stack and other info is recorded in the linked .edn file.

The repeated syntax error line is because both lein and clojure.main are printing the error. There are a variety of options to fix that, but they are really up to what Leiningen wants to do. In my opinion, Leiningen should be wrapping the subprocess entry point more and not be dependent on what clojure.main does as a runner. The error reporting facility is provided as a separate function that Leiningen could use if desired (see new http://clojure.github.io/clojure/branch-master/clojure.main-api.html#clojure.main/report-error).

This affects anything in lein that shells to a subprocess calling clojure.main (which is many things - compile, test, run, ring server, etc).

14

u/metamorphisteles Apr 11 '19

This looks great.

4

u/zcaudate Apr 12 '19

this is great. that's a really cool feature.

1

u/jeronimo78543 Apr 15 '19

It looks great indeed!

However, for CI, is there a way to turn the verbose error back on? The stacktrace is otherwise not available in environment where it might provide essential information.

1

u/alexdmiller Apr 15 '19

As mentioned elsewhere in this thread, yes.

3

u/[deleted] Apr 13 '19

[removed] — view removed comment

2

u/alexdmiller Apr 14 '19

There is a new switch on clojure.main --report-stderr to force a report to stderr. I'm now reconsidering whether that should be a Java system property, which would allow it to be set via :jvm-opts in Leiningen (without needing any additional changes in lein).

As far as Leiningen goes, I want to repeat again - it is entirely up to lein how it launches sub-processes and handles errors. lein is currently leaving this totally up to clojure.main and is thus subject to the whims of how clojure.main behavior works, but there is no reason that needs to be so. It could launch processes in a shim that catches errors in any way it likes, including the use of custom error printers, stack trace printer/filterers, colorizers, interactive error debug, etc.

4

u/[deleted] Apr 14 '19

[removed] — view removed comment

1

u/alexdmiller Apr 14 '19

The changes here are only related to programs launched via clojure.main (not interactive repls). The clojure.main repl has never printed stack traces (some others do). In an interactive mode you have the opportunity to further inspect state, by looking at *e or calling pst, etc.

So the scope of change here is only non-interactive and we have decided the default should be that stack traces should not be printed. Other options are: print to stderr, write to temp file, and do nothing. The part I’m reconsidering is: should we have slightly more options available, and how should that be configured. Currently it’s a clojure.main flag but a Java system property may be more amenable to existing callers like Leiningen.

2

u/[deleted] Apr 15 '19

[removed] — view removed comment

1

u/alexdmiller Apr 15 '19

I don’t think that’s a discernible thing from within the Java process?

1

u/victorbjelkholm Apr 14 '19

The temp directory is usually mounted as tmpfs, which is just in memory, it's not actually on disk. Once you reboot (or earlier sometimes), it'll be all gone.

better solved by a switch if the full stack trace is necessary

Seems like Clojure would have to know which full stack traces are necessary vs not, which I think is up to the developer, not the implementation of Clojure. Maybe I missunderstood what you meant.

3

u/[deleted] Apr 14 '19

[removed] — view removed comment

2

u/seancorfield Apr 15 '19

If you write a Clojure process, you have complete control over how your main entry point handles exceptions so you can choose to report them to stderr yourself.

If you're running a Clojure process you did not write and don't control, there's an option to force clojure.main to report the full error/stacktrace to stderr.

Either way, you can satisfy DevOps without needing the temp file.

If you're running stuff like tests locally or other dev-related processes, you get nice, clean output and you don't have to scroll back several pages just to see what test failures you got, for example!

We have 1.10.1 Beta 1 in production and Beta 2 in dev and the shorter error messages are a great improvement as a dev/test experience.