If abort() is called with a message, like in the code below, and output.aborts is True (default), then the message is displayed twice.
from fabric.api import abort, task
This is the output of fab test:
Fatal error: Mxyzptlk
This behavior was introduced by 96043d6. Not sure why though.
I propose either to roll it back or, if there is a good reason for that change, make it to something like this:
sys.exit(1 if output.aborts else msg)
PS: I've also reported this issue on fab-user mailing list back in March 13th
Include error message in task abort exception
I've been noticing this myself too, it is pretty annoying. Thanks for bringing it up again.
Dug up its source, which is #1213, wherein my feedback focused on whether it would change the exit code, and totally missed the printing angle. My mistake.
I think a different update than the one you suggest is required. The use case for #1213 seemed to be "I am catching SystemExit above Fabric-using code & want to see the abort message", and my guess is that's irrespective of whether one has aborts active (eg perhaps they're running it headless & want some metadata, such as "what happened with this particular job", stored separately from the raw stdout/stderr).
In other words, the conflation of additional metadata in the exception, with the print behavior, is our problem.
Dug into exactly how sys.exit and SystemException work; under Python 2.6.9 the following appears true:
From outside the process, sys.exit(arg) and raise SystemExit(arg) behave identically, including exit code and automatically printed-to-stderr values if it is a string, etc. This was expected from the docs.
Introspection shows that SystemExit objects created by either of those methods, have distinct code and message attributes, and that they always contain identical values when generated in the above manner (i.e., arg).
However, one can do the following to obtain a SystemExit whose code and message are distinct, and furthermore the message is not printed to stderr (implying that the printing is driven by code, not message), which is exactly what I think we want here:
e = SystemExit()
e.code = 1
e.message = "oh dear"
So I think updating abort to use the above lets us have our cake and eat it too - @ipanousis would still be able to inspect e.message in his except clause, but we would bypass sys.exit's printing behavior.
I will implement this now. Should users identify problems with this approach, I am leaning towards reverting the original patch (or going for your meets-it-halfway suggestion), the benefits don't outweigh the ugly.
Test proving #1318
Add another test re: #1318, re #1213.
Also tweak previous test. Not sure why newline was different this time.
Changelog re #1318