Skip to content

Commit

Permalink
Merge pull request #220 from jglick/printStackTrace
Browse files Browse the repository at this point in the history
Do not printStackTrace on an exception you are going to rethrow
  • Loading branch information
bitwiseman authored Dec 16, 2020
2 parents a7bc79e + 7b30abd commit 6b0901b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
40 changes: 20 additions & 20 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ protected void computeChildren(final ChildObserver<P> observer, final TaskListen
try {
sourceActions.put(source.getId(), source.fetchActions(null, listener));
} catch (IOException | InterruptedException | RuntimeException e) {
printStackTrace(e, listener.error("[%tc] Could not update folder level actions from source %s",
System.currentTimeMillis(), source.getId()));
listener.error("[%tc] Could not update folder level actions from source %s",
System.currentTimeMillis(), source.getId());
throw e;
}
}
Expand All @@ -613,17 +613,17 @@ protected void computeChildren(final ChildObserver<P> observer, final TaskListen
try {
bc.commit();
} catch (IOException | RuntimeException e) {
printStackTrace(e, listener.error("[%tc] Could not persist folder level actions",
System.currentTimeMillis()));
listener.error("[%tc] Could not persist folder level actions",
System.currentTimeMillis());
throw e;
}
if (saveProject) {
try {
save();
} catch (IOException | RuntimeException e) {
printStackTrace(e, listener.error(
listener.error(
"[%tc] Could not persist folder level configuration changes",
System.currentTimeMillis()));
System.currentTimeMillis());
throw e;
}
}
Expand All @@ -636,8 +636,8 @@ protected void computeChildren(final ChildObserver<P> observer, final TaskListen
source.fetch(new SCMHeadObserverImpl(source, observer, listener, _factory,
new IndexingCauseFactory(), null), listener);
} catch (IOException | InterruptedException | RuntimeException e) {
printStackTrace(e, listener.error("[%tc] Could not fetch branches from source %s",
System.currentTimeMillis(), source.getId()));
listener.error("[%tc] Could not fetch branches from source %s",
System.currentTimeMillis(), source.getId());
throw e;
}
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ p.new SCMHeadObserverImpl(
} catch (IOException e) {
printStackTrace(e, listener.error(e.getMessage()));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
} finally {
long end = System.currentTimeMillis();
Expand All @@ -1368,8 +1368,8 @@ p.new SCMHeadObserverImpl(
printStackTrace(e, global.error("[%tc] %s encountered an error while processing %s %s event from %s with timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType, eventOrigin, eventTimestamp));
} catch (InterruptedException e) {
printStackTrace(e, global.error("[%tc] %s was interrupted while processing %s %s event from %s with timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType, eventOrigin, eventTimestamp));
global.error("[%tc] %s was interrupted while processing %s %s event from %s with timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType, eventOrigin, eventTimestamp);
throw e;
}
}
Expand Down Expand Up @@ -1618,7 +1618,7 @@ p.new SCMHeadObserverImpl(
} catch (IOException e) {
printStackTrace(e, listener.error(e.getMessage()));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
} finally {
long end = System.currentTimeMillis();
Expand All @@ -1633,10 +1633,10 @@ p.new SCMHeadObserverImpl(
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType,
eventOrigin, eventTimestamp));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType,
eventOrigin, eventTimestamp));
eventOrigin, eventTimestamp);
throw e;
}
} else {
Expand Down Expand Up @@ -1686,7 +1686,7 @@ p.new SCMHeadObserverImpl(
} catch (IOException e) {
printStackTrace(e, listener.error(e.getMessage()));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
} finally {
long end = System.currentTimeMillis();
Expand All @@ -1702,11 +1702,11 @@ p.new SCMHeadObserverImpl(
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType,
eventOrigin, eventTimestamp));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with "
+ "timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p), eventDescription, eventType,
eventOrigin, eventTimestamp));
eventOrigin, eventTimestamp);
throw e;
}
}
Expand Down Expand Up @@ -1802,7 +1802,7 @@ public void onSCMSourceEvent(SCMSourceEvent<?> event) {
} catch (IOException e) {
printStackTrace(e, listener.error(e.getMessage()));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
}
} catch (IOException e) {
Expand All @@ -1813,12 +1813,12 @@ public void onSCMSourceEvent(SCMSourceEvent<?> event) {
eventDescription, event.getType().name(),
event.getOrigin(), event.getTimestamp()));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with "
+ "timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p),
eventDescription, event.getType().name(),
event.getOrigin(), event.getTimestamp()));
event.getOrigin(), event.getTimestamp());
throw e;
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/jenkins/branch/OrganizationFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,17 @@ protected void computeChildren(final ChildObserver<MultiBranchProject<?,?>> obse
try {
bc.commit();
} catch (IOException | RuntimeException e) {
printStackTrace(e, listener.error("[%tc] Could not persist folder level actions",
System.currentTimeMillis()));
listener.error("[%tc] Could not persist folder level actions",
System.currentTimeMillis());
throw e;
}
if (saveProject) {
try {
save();
} catch (IOException | RuntimeException e) {
printStackTrace(e, listener.error(
listener.error(
"[%tc] Could not persist folder level configuration changes",
System.currentTimeMillis()));
System.currentTimeMillis());
throw e;
}
}
Expand All @@ -541,8 +541,8 @@ protected void computeChildren(final ChildObserver<MultiBranchProject<?,?>> obse
try {
navigator.visitSources(new SCMSourceObserverImpl(listener, observer, navigator, (SCMSourceEvent<?>) null));
} catch (IOException | InterruptedException | RuntimeException e) {
printStackTrace(e, listener.error("[%tc] Could not fetch sources from navigator %s",
System.currentTimeMillis(), navigator));
listener.error("[%tc] Could not fetch sources from navigator %s",
System.currentTimeMillis(), navigator);
throw e;
}
}
Expand Down Expand Up @@ -1166,7 +1166,7 @@ p.new SCMSourceObserverImpl(listener, childObserver, navigator, event),
} catch (IOException e) {
printStackTrace(e, listener.error(e.getMessage()));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
} finally {
long end = System.currentTimeMillis();
Expand All @@ -1184,12 +1184,12 @@ p.new SCMSourceObserverImpl(listener, childObserver, navigator, event),
globalEventDescription, event.getType().name(),
event.getOrigin(), event.getTimestamp()));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with "
+ "timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p),
globalEventDescription, event.getType().name(),
event.getOrigin(), event.getTimestamp()));
event.getOrigin(), event.getTimestamp());
throw e;
}
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@ public void onSCMNavigatorEvent(SCMNavigatorEvent<?> event) {
printStackTrace(e,
listener.error("Could not fetch metadata from %s", navigator));
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
}
}
Expand Down Expand Up @@ -1285,12 +1285,12 @@ public void onSCMNavigatorEvent(SCMNavigatorEvent<?> event) {
event.getClass().getName(), event.getType().name(),
event.getOrigin(), event.getTimestamp()));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with "
+ "timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p),
event.getClass().getName(), event.getType().name(),
event.getOrigin(), event.getTimestamp()));
event.getOrigin(), event.getTimestamp());
throw e;
}
}
Expand Down Expand Up @@ -1356,7 +1356,7 @@ p.new SCMSourceObserverImpl(listener, childObserver, n,
}
}
} catch (InterruptedException e) {
printStackTrace(e, listener.error(e.getMessage()));
listener.error(e.getMessage());
throw e;
} finally {
long end = System.currentTimeMillis();
Expand All @@ -1375,12 +1375,12 @@ p.new SCMSourceObserverImpl(listener, childObserver, n,
event.getClass().getName(), event.getType().name(),
event.getOrigin(), event.getTimestamp()));
} catch (InterruptedException e) {
printStackTrace(e, global.error(
global.error(
"[%tc] %s was interrupted while processing %s %s event from %s with "
+ "timestamp %tc",
System.currentTimeMillis(), ModelHyperlinkNote.encodeTo(p),
event.getClass().getName(), event.getType().name(),
event.getOrigin(), event.getTimestamp()));
event.getOrigin(), event.getTimestamp());
throw e;
}
}
Expand Down Expand Up @@ -1507,7 +1507,7 @@ public void complete() throws IllegalStateException, IOException, InterruptedExc
} catch (InterruptedException | IOException x) {
throw x;
} catch (Exception x) {
x.printStackTrace(listener.error("Failed to create or update a subproject " + projectName));
printStackTrace(x, listener.error("Failed to create or update a subproject " + projectName));
}
}

Expand Down

0 comments on commit 6b0901b

Please sign in to comment.