pgm: propagate generic exceptions when throwing Die exception

If a command is stopped by throwing a Die exception since a generic
exception was caught this exception contains additional information
which is not available in the error message. Hence chain it to the Die
exception in order to allow printing a complete stacktrace including
causes to the error stream of the JGit command line by adding option
--show-stack-trace, e.g.

$ jgit --show-stack-trace commit -m "test"

Change-Id: I7ad8c56b997ab60d2bd08f4e7b4d0b80c84021c3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2019-01-16 01:13:38 +01:00
parent d4d9625d4b
commit 159968abc4
3 changed files with 6 additions and 6 deletions

View File

@ -96,11 +96,11 @@ protected void run() throws Exception {
if (output != null)
cmd.setFilename(output);
cmd.call();
} catch (GitAPIException e) {
throw die(e.getMessage());
}
} catch (GitAPIException e) {
throw die(e.getMessage(), e);
}
} catch (FileNotFoundException e) {
throw die(e.getMessage());
throw die(e.getMessage(), e);
} finally {
if (output != null && stream != null)
stream.close();

View File

@ -110,7 +110,7 @@ protected void run() throws Exception {
Constants.OS_USER_DIR), localName);
} catch (IllegalArgumentException e) {
throw die(MessageFormat.format(
CLIText.get().cannotGuessLocalNameFrom, sourceUri));
CLIText.get().cannotGuessLocalNameFrom, sourceUri), e);
}
} else
localNameF = new File(localName);

View File

@ -196,7 +196,7 @@ private Charset getLogOutputEncodingCharset(Repository repository) {
try {
return Charset.forName(logOutputEncoding);
} catch (IllegalArgumentException e) {
throw die(CLIText.get().cannotCreateOutputStream);
throw die(CLIText.get().cannotCreateOutputStream, e);
}
}
}