From a876f058952a2523531a0fa424c749d059ab665d Mon Sep 17 00:00:00 2001 From: Sverker Abrahamsson Date: Wed, 13 Sep 2017 11:40:49 +0200 Subject: [PATCH] Catch Throwable instead of Exception in the catch-all clause, as that will catch also java.lang.Error Catch also Error on some locations where IOException is catched, as the github lib sometimes will catch IOException and wrap it in an Error --- .../jenkinsci/plugins/ghprb/GhprbPullRequest.java | 15 +++++++++++++-- .../jenkinsci/plugins/ghprb/GhprbRootAction.java | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java index 63fd68c83..9c133243b 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java @@ -178,6 +178,8 @@ private void checkBlackListLabels() { shouldRun = false; } } + } catch(Error e) { + logger.log(Level.SEVERE, "Failed to read blacklist labels", e); } catch(IOException e) { logger.log(Level.SEVERE, "Failed to read blacklist labels", e); } @@ -202,6 +204,8 @@ private void checkWhiteListLabels() { logger.log(Level.INFO, "Can't find any of whitelist label."); shouldRun = false; } + } catch(Error e) { + logger.log(Level.SEVERE, "Failed to read whitelist labels", e); } catch(IOException e) { logger.log(Level.SEVERE, "Failed to read whitelist labels", e); } @@ -317,8 +321,9 @@ else if (comment != null) { ); } } - } - catch (IOException ex) { + } catch (Error e) { + logger.log(Level.SEVERE, "Exception caught while updating the PR", e); + } catch (IOException ex) { logger.log(Level.SEVERE, "Exception caught while updating the PR", ex); } } @@ -375,6 +380,8 @@ private GitUser getPRCommitAuthor (){ return commitDetails.getCommit().getCommitter(); } } + } catch (Error e) { + logger.log(Level.INFO, "Unable to get PR commits: ", e); } catch (Exception ex) { logger.log(Level.INFO, "Unable to get PR commits: ", ex); } @@ -584,6 +591,8 @@ private int checkComments(GHPullRequest ghpr, } } } + } catch (Error e) { + logger.log(Level.SEVERE, "Couldn't obtain comments.", e); } catch (IOException e) { logger.log(Level.SEVERE, "Couldn't obtain comments.", e); } @@ -606,6 +615,8 @@ public boolean checkMergeable() { isMergeable = pr.getMergeable(); } mergeable = isMergeable != null && isMergeable; + } catch (Error e) { + logger.log(Level.SEVERE, "Couldn't obtain mergeable status.", e); } catch (IOException e) { logger.log(Level.SEVERE, "Couldn't obtain mergeable status.", e); } diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java index 06ad17ffc..383619982 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java @@ -250,13 +250,13 @@ private void triggerPr(final GhprbTrigger trigger, public void run() { try { trigger.handlePR(pr); - } catch (Exception e) { + } catch (Throwable th) { StringBuilder sb = new StringBuilder(); sb.append("Unable to handle PR# "); sb.append(pr.getNumber()); sb.append(" for repo: "); sb.append(pr.getRepository().getFullName()); - logger.log(Level.SEVERE, sb.toString(), e); + logger.log(Level.SEVERE, sb.toString(), th); } } }.start();