-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
[FIXED JENKINS-26964] Handle AbortException right #1577
Conversation
e.printStackTrace(listener.error(msg)); | ||
if (!(e instanceof AbortException)){ | ||
e.printStackTrace(listener.error(msg)); | ||
} | ||
LOGGER.log(WARNING, msg, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why print the stack trace in the log for Aborts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read code again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not talking about the build log (listener) but the Jenkins log Logger.log(..) which is called outside the if() statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, i can move it to if.
a6d989f
to
6198db7
Compare
Fixed comment, fixup'ed into one commit. |
How about overriding
|
@ikedam 👎 |
👍 |
@ikedam |
@oleg-nenashev to which log? No need to print stacktrace into listener, this is known and handled exception. |
p.getPublishersList().add(new ArtifactArchiver("result.txt", "", false)); | ||
|
||
FreeStyleBuild b = p.scheduleBuild2(0).get(); | ||
assertEquals("Build must fail, because we used FalsePublisher", b.getResult(), Result.FAILURE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FalsePublisher
-> AbortExceptionPublisher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
FWIW, the |
@orrc interesting, maybe something changed in core. I will try re-trigger PR-build |
👍 |
@@ -733,8 +734,10 @@ protected final boolean performAllBuildSteps(BuildListener listener, Iterable<? | |||
|
|||
private void reportError(BuildStep bs, Throwable e, BuildListener listener, boolean phase) { | |||
String msg = "Publisher " + bs.getClass().getName() + " aborted due to exception"; | |||
e.printStackTrace(listener.error(msg)); | |||
LOGGER.log(WARNING, msg, e); | |||
if (!(e instanceof AbortException)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is an AbortException
, is the message being printed somewhere else already? It needs to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equivalent pattern in the past (of returning false
from the perform()
method) left no message, so the patch is consistent with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks also weird for me. Will double-check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equivalent pattern in the past (of returning
false
from theperform()
method) left no message
Sure, but then the plugin author was deciding to leave no message (or more likely to print one to a BuildListener
earlier). If they decided to throw AbortException
, they supplied a message, so we should use it.
👍 |
assertEquals("Build must fail, because we used FalsePublisher", b.getResult(), Result.FAILURE); | ||
File file = new File(b.getArtifactsDir(), "result.txt"); | ||
assertTrue("ArtifactArchiver is executed even prior publisher fails.", file.exists()); | ||
assertTrue("Second publisher must see FAILURE status", FileUtils.readFileToString(file).equals(Result.FAILURE.toString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I would expect to see the detail message from the AbortException
in the log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be able to
j.assertBuildStatusNotContains("\tat ", b);
to prove that we suppressed the stack trace.
Tests do pass for me. |
@Override | ||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { | ||
FilePath file = build.getWorkspace().child(fileName); | ||
file.write(build.getResult().toString(), Charset.defaultCharset().name()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, though it would be slightly more concise to just print the result in a specially-formatted message to the listener
. Then you can use JenkinsRule.assertBuildLogContains
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…though perhaps not, since you seem to be assuming that a following ArtifactArchiver
will see it, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interaction with files is not ideal, but it works very well. buildlog can be screwed or has something wrong. File is strict.
Reviewed. I would be 👍 if |
Thanks for super review :) I will fix comments |
6198db7
to
545e123
Compare
- Print publisher display name instead of class, so user can understand what publisher in UI was used and failed. - Setter for artifact archiver shows how it handle status - Minor typos - Added test for stacktraces in build log
545e123
to
92734a8
Compare
} catch (LinkageError e) { | ||
reportError(bs, e, listener, phase); | ||
r = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performAllBuildSteps
is ignored in most calls, but i think this should add consistency for failed execution
Also rebased and noted 😅 |
@@ -723,21 +725,33 @@ protected final boolean performAllBuildSteps(BuildListener listener, Iterable<? | |||
try { | |||
if (!perform(bs,listener)) { | |||
LOGGER.log(Level.FINE, "{0} : {1} failed", new Object[] {AbstractBuild.this, bs}); | |||
setResult(Result.FAILURE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not need to be conditional on phase
, like it is in reportError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to have consistency.
- Typo - Print error combined - Set result only when phase like in other code parts. - Test for expected error message in log
The last PR build failed randomly (timeout after the notorious Credentials-related errors I can never track down), so submitted for validated merge rather than merging immediately. |
String msg = "Publisher " + bs.getClass().getName() + " aborted due to exception"; | ||
e.printStackTrace(listener.error(msg)); | ||
LOGGER.log(WARNING, msg, e); | ||
final String publisher = ((Publisher) bs).getDescriptor().getDisplayName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, IDE or static analysing tools didn't highlight this code.
JENKINS-26964