aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-02-08 15:23:04 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-02-09 12:16:52 +0000
commit913d0f5addc3b315bbd812e0496e564834fe9468 (patch)
tree2fee66945fe6c0d99196252c039f2e4a612cf4f7 /src
parent51a204a8e4cc253d1fb31d51286968ef8e63a999 (diff)
Make jGit print a better error message
Improves the situation described in #853, so people don't have to patch in a runtime exception to actually find out what jGit's complaining about. -- MOS_MIGRATED_REVID=114107775
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
index c4a98c5818..ecc7f8d483 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
@@ -161,13 +161,23 @@ public class GitCloner {
new IOException("Invalid branch, tag, or commit: " + e.getMessage()),
Transience.PERSISTENT);
} catch (GitAPIException e) {
+ // This is a sad attempt to actually get a useful error message out of jGit, which will bury
+ // the actual (useful) cause of the exception under several throws.
+ StringBuilder errmsg = new StringBuilder();
+ errmsg.append(e.getMessage());
+ Throwable throwable = e;
+ while (throwable.getCause() != null) {
+ throwable = throwable.getCause();
+ errmsg.append(" caused by " + e.getMessage());
+ }
throw new RepositoryFunctionException(
- new IOException("Error cloning repository: " + e.getMessage()), Transience.PERSISTENT);
+ new IOException("Error cloning repository: " + errmsg), Transience.PERSISTENT);
} catch (JGitInternalException e) {
// This is a lame catch-all for jgit throwing RuntimeExceptions all over the place because,
// as the docs put it, "a lot of exceptions are so low-level that is is unlikely that the
// caller of the command can handle them effectively." Thanks, jgit.
- throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.PERSISTENT);
+ throw new RepositoryFunctionException(new IOException(e.getMessage()),
+ Transience.PERSISTENT);
} finally {
if (git != null) {
git.close();