Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #523 #570

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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);
}
Expand All @@ -206,6 +208,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);
}
Expand Down Expand Up @@ -321,8 +325,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);
}
}
Expand Down Expand Up @@ -379,6 +384,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);
}
Expand Down Expand Up @@ -588,6 +595,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);
}
Expand All @@ -610,6 +619,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ private void triggerPr(final GhprbTrigger trigger,
public void run() {
try {
trigger.handlePR(pr);
} catch (Exception e) {
} catch (Throwable th) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I've been told catching Throwable is a bad idea. Can a more seasoned Jenkins dev review this PR?

cc @jenkinsci/code-reviewers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intention here is to catch Exception and Error, then check for those types and if it's not either of those types then rethrow throwable. I'm just concerned that we're swallowing all throwable.

Copy link
Member

@samrocketman samrocketman Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a quote from the java.lang.Error javadoc:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

I need an adult 🆘

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bad style for sure. But, you know, throwing it from the code is a bad idea as well :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice the main things it is problematic to catch are OutOfMemoryError (generally no practical recovery, so does not make much difference either way); and ThreadDeath (you need to be sure to rethrow quickly at least).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open up a followup PR @jglick. I guess I merged too quickly.

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();
Expand Down