Skip to content

Commit

Permalink
Merge pull request #92 from Entea/proper_cli_error_exit_code
Browse files Browse the repository at this point in the history
Exit with status 1 on error
  • Loading branch information
hrj committed Sep 7, 2016
2 parents 0f0ddf9 + d7bd3e3 commit a9663ef
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions cli/src/main/scala/co/uproot/abandon/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ object CLIMain {
def runAppThrows(args: Array[String]) {
val settingsResult = SettingsHelper.getCompleteSettings(args)
settingsResult match {
case Left(errorMsg) => Console.err.println("Error: " + errorMsg)
case Left(errorMsg) => printErrAndExit(errorMsg)
case Right(settings) =>
val (parseError, astEntries, processedFiles) = Processor.parseAll(settings.inputs)
if (!parseError) {
Expand Down Expand Up @@ -208,21 +208,20 @@ object CLIMain {
try {
runAppThrows(args)
} catch {
case a: AssertionError => printErr("Error: " + a.getMessage)
case i: InputError => printErr("Input error: " + i.getMessage)
case i: ConstraintError => printErr("Constraint Failed: " + i.getMessage)
case e: NotImplementedError => printErr("Some functionality has not yet been implemented. We intend to implement it eventually. More details:\n" + e.getMessage)
case e: Error => printErr("Unexpected error", e)
case a: AssertionError => printErrAndExit("Error: " + a.getMessage)
case i: InputError => printErrAndExit("Input error: " + i.getMessage)
case i: ConstraintError => printErrAndExit("Constraint Failed: " + i.getMessage)
case e: NotImplementedError => printErrAndExit("Some functionality has not yet been implemented. We intend to implement it eventually. More details:\n" + e.getMessage)
case e: Error => printErrAndExit("Unexpected error", e)
}
}

def printErr(msg: String) = {
def printErrAndExit(msg: String, err:Error = null) = {
println(Console.RED + Console.BOLD + msg + Console.RESET)
}

def printErr(msg: String, err:Error) = {
println(Console.RED + Console.BOLD + msg + Console.RESET)
err.printStackTrace(Console.out)
if (err != null) {
err.printStackTrace(Console.out)
}
System.exit(1)
}
}

Expand Down

0 comments on commit a9663ef

Please sign in to comment.