librelist archives

« back to archive

Plugin authors: change in error handling

Plugin authors: change in error handling

From:
Phil Hagelberg
Date:
2012-08-06 @ 23:36
Greetings folks.

We had a recent change to the logic around task failure that I failed
to communicate to plugin authors.

In Leiningen 1.x, having a task function return a numeric value was a
way to signal the process's exit code. This worked OK, but it was easy
to make mistakes where failures would go ignored. In addition, it's
reasonable to expect task functions to be able to return arbitrary
values, so treating integers specially was a confusing special case.

In Leiningen 2.x, tasks should call the `leiningen.core.main/abort`
function when a fatal error is encountered. If the
`leiningen.core.main/*exit-process?*` var is bound to true, then this
will trigger an exit, but in some contexts (like `with-profiles`) it
will simply trigger an exception and go on to the next task.

I have a pull request for leinjacker which provides an abort function
with compatibility across Leiningen 1.x and 2.x; this should aid in
writing plugins which work with both versions:

https://github.com/sattvik/leinjacker/pull/5

My apologies for not communicating this earlier.

-Phil

Re: Plugin authors: change in error handling

From:
Sean Corfield
Date:
2012-08-07 @ 00:45
On Mon, Aug 6, 2012 at 4:36 PM, Phil Hagelberg <phil@hagelb.org> wrote:
> In Leiningen 2.x, tasks should call the `leiningen.core.main/abort`
> function when a fatal error is encountered. If the
> `leiningen.core.main/*exit-process?*` var is bound to true, then this
> will trigger an exit, but in some contexts (like `with-profiles`) it
> will simply trigger an exception and go on to the next task.

FWIW, lein-expectations was updated this morning - to 0.0.7 - to
include what I hope is a fix for this change. It now calls abort if
there any failures / errors in tests. However, it's still not clear
how multi-version testing will be affected by this. Specifically:
* in a multi-version test for, say, Clojure 1.2, 1.3, 1.4
* if a test fails against 1.2 and the plugin calls abort
* testing seems to proceed to 1.3 and 1.4 (which may pass)
* will Leiningen exit with a status code of 1 at that point (because
one task failed) or 0?

This is important for running multi-version testing in build scripts.

If abort simply causes Leiningen to print a warning and move on to the
next task, but later exit with a zero status code, then this forces
testing plugins to re-bind *exit-process?* to true before they call
abort which is kinda ugly (and prevents multi-version testing from
running later version tests if an early version test fails).
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)