From 159968abc4fad1546ff7651450067b8cbce3bf2a Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 16 Jan 2019 01:13:38 +0100 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/pgm/Archive.java | 8 ++++---- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java | 2 +- .../src/org/eclipse/jgit/pgm/TextBuiltin.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java index 4721b3a0f..cb63a9a06 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java @@ -96,11 +96,11 @@ class Archive extends TextBuiltin { 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(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 393c607a2..fe2462012 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -110,7 +110,7 @@ class Clone extends AbstractFetchCommand implements CloneCommand.Callback { 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); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index c4b4018b8..05f237837 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -196,7 +196,7 @@ public abstract class TextBuiltin { try { return Charset.forName(logOutputEncoding); } catch (IllegalArgumentException e) { - throw die(CLIText.get().cannotCreateOutputStream); + throw die(CLIText.get().cannotCreateOutputStream, e); } } }