Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optional msg argument to leiningen.core.main/exit. Use it for abort. #1437

Merged
merged 1 commit into from

4 participants

@laurentpetit
  • New signature: leiningen.core.main/exit [exit-code & msg]
  • msg used when exit-process? is false as the Exception message

The following issues have been created for projects which are (lein-junit, test2junit) or might (pallet/pallet, pallet/nrepl-main) be impacted by this change:

@laurentpetit laurentpetit Optional msg argument to leiningen.core.main/exit. Use it for abort.
- New signature: leiningen.core.main/exit [exit-code & msg]
- msg used when *exit-process?* is false as the Exception message
c28f03a
@benwbooth

Would it be possible to print nothing instead of "Suppressed exit" if no message is provided? I'm using lein exec with grenchman to run clojure command-line scripts. Right now, every script always prints a "Suppressed exit" message when the script exits, which is really annoying. The only workaround I've found is to exit scripts explicitly using (throw (ex-info nil {:exit-code 0 :suppress-msg true})). This is quite ugly. I'd much rather be able to say (exit 0) or (leiningen.core.main/exit 0). Since an abort message can now be explicitly provided, I think it makes sense to not display anything by default.

@laurentpetit

As far as I can tell, leiningen.core.main/exit doesn't print anything to stderr, it's leiningen.core.main/abort which does that (even after the pull request).
Maybe this can be handled as a separate issue.

@benwbooth

The "Suppressed exit" gets printed to stdout on line 322 of leiningen.core.main/-main, when the exit exception is caught. But this only happens if *exit-process?* is set to false.

@hyPiRion
Collaborator

I was thinking it would be reasonable to somehow ensure that you can detect that this was thrown by Leiningen's abort/exit function. Something like the #1440 :suppress-msg true might work, but I think we have to be a bit careful with respect to backwards compatibility. Perhaps even wait until 3.0? Not sure, Phil probably has a better idea on what is sensible or not.

I think another change here is that abort messages will be printed twice in some core commands, although I am not completely sure about that. I'll have a look into that later.

The pull request itself seems good, though. I just think the implications has to be considered. =)

@technomancy technomancy merged commit c28f03a into from
@technomancy
Owner

Sorry for the delay on this. Just merged it in. There were a few weird situations where this affected the tests, but I don't think there will be much in the way of compatibility issues affecting plugins.

@febeling febeling referenced this pull request in febeling/lein-junit
Closed

Test file detection pattern should be an option #24

@febeling febeling referenced this pull request from a commit in febeling/lein-junit
@febeling febeling Fix tests for exit suppression 1479b59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2014
  1. @laurentpetit

    Optional msg argument to leiningen.core.main/exit. Use it for abort.

    laurentpetit authored
    - New signature: leiningen.core.main/exit [exit-code & msg]
    - msg used when *exit-process?* is false as the Exception message
This page is out of date. Refresh to see the latest.
View
9 leiningen-core/src/leiningen/core/main.clj
@@ -107,11 +107,14 @@
"Exit the process. Rebind *exit-process?* in order to suppress actual process
exits for tools which may want to continue operating. Never call
System/exit directly in Leiningen's own process."
- ([exit-code]
+ ([exit-code & msg]
(if *exit-process?*
(do (shutdown-agents)
(System/exit exit-code))
- (throw (ex-info "Suppressed exit" {:exit-code exit-code}))))
+ (throw (ex-info (if (seq msg)
+ (apply print-str msg)
+ "Suppressed exit")
+ {:exit-code exit-code}))))
([] (exit 0)))
(defn abort
@@ -121,7 +124,7 @@
(binding [*out* *err*]
(when (seq msg)
(apply println msg))
- (exit 1)))
+ (apply exit 1 msg)))
(defn- next-dist-row [s t x pprev prev]
(let [t-len (count t)
View
2  leiningen-core/test/leiningen/core/test/helper.clj
@@ -9,5 +9,5 @@
(try
(apply f args)
(catch clojure.lang.ExceptionInfo e
- (when-not (= "Suppressed exit" (.getMessage e))
+ (when-not (:exit-code (ex-data e))
(throw e)))))))
Something went wrong with that request. Please try again.