ErrorProne: Fix UnusedException errors
When the UnusedException check is enabled, the build fails with:
[UnusedException] This catch block catches an symbol and re-throws
another, but swallows the caught symbol rather than setting it as a
cause. This can make debugging harder.
Fix it by setting the caught exception as cause on the subsequently
thrown exception.
Note: The grammatically incorrect error message is copy-pasted as-is
from the version of ErrorProne currently used in Bazel; it has been
fixed by [1] in the latest version.
[1] https://github.com/google/error-prone/commit/d57a39c
Change-Id: I0139249b992e70e47db1f8213dbc8ce80c445128
diff --git a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/CannotDeleteProjectException.java b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/CannotDeleteProjectException.java
index 3cf3912..04e98bf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/CannotDeleteProjectException.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/CannotDeleteProjectException.java
@@ -22,7 +22,7 @@
super(message);
}
- public CannotDeleteProjectException(Exception e) {
- super(e);
+ public CannotDeleteProjectException(String message, Throwable why) {
+ super(message, why);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeletePreconditions.java b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeletePreconditions.java
index 30474e4..05842c4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeletePreconditions.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeletePreconditions.java
@@ -128,7 +128,7 @@
}
} catch (StorageException e) {
throw new CannotDeleteProjectException(
- String.format("Unable to verify if '%s' has open changes.", projectNameKey.get()));
+ String.format("Unable to verify if '%s' has open changes.", projectNameKey.get()), e);
}
}
}
@@ -139,7 +139,7 @@
children = listChildProjectsProvider.get().withLimit(1).apply(rsrc).value();
} catch (Exception e) {
throw new CannotDeleteProjectException(
- String.format("Unable to verify if '%s' has children projects.", rsrc.getName()));
+ String.format("Unable to verify if '%s' has children projects.", rsrc.getName()), e);
}
if (!children.isEmpty()) {
throw new CannotDeleteProjectException(
@@ -166,7 +166,7 @@
// we're trying to delete the repository,
// so this exception should not stop us
} catch (IOException | SubmoduleException e) {
- throw new CannotDeleteProjectException("Project is subscribed by other projects.");
+ throw new CannotDeleteProjectException("Project is subscribed by other projects.", e);
}
}
@@ -184,7 +184,8 @@
String.format("Project %s has tags", projectNameKey));
}
} catch (IOException e) {
- throw new CannotDeleteProjectException(e);
+ throw new CannotDeleteProjectException(
+ String.format("Unable to verify if project %s has tags", projectNameKey), e);
}
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeleteProject.java b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeleteProject.java
index f8e4c2b..4b36826 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeleteProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/DeleteProject.java
@@ -88,7 +88,7 @@
try {
fsHandler.delete(project, preserve);
} catch (RepositoryNotFoundException e) {
- throw new ResourceNotFoundException();
+ throw new ResourceNotFoundException(project.getName(), e);
}
cacheHandler.delete(project);
} else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/HideProject.java b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/HideProject.java
index b2af2c2..c5bf8ce 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/HideProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/HideProject.java
@@ -77,7 +77,7 @@
projectConfig.commit(md);
projectCache.evict(projectConfig.getProject());
} catch (RepositoryNotFoundException e) {
- throw new ResourceNotFoundException();
+ throw new ResourceNotFoundException(rsrc.getNameKey().get(), e);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(e.getMessage());
}
@@ -89,7 +89,7 @@
createProject.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(projectName), null);
} catch (RestApiException | ConfigInvalidException | PermissionBackendException e) {
throw new ResourceConflictException(
- String.format("Failed to create project %s", projectName));
+ String.format("Failed to create project %s", projectName), e);
}
}
}