From 913d0f5addc3b315bbd812e0496e564834fe9468 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Mon, 8 Feb 2016 15:23:04 +0000 Subject: 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 --- .../devtools/build/lib/bazel/repository/GitCloner.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/google') 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(); -- cgit v1.2.3