Skip to content

Commit

Permalink
Ensure we always call getContext().onFailure() in stop
Browse files Browse the repository at this point in the history
  • Loading branch information
mrginglymus committed Jan 27, 2021
1 parent 629cd7e commit 8215be6
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ ChecksInfo extractChecksInfo() {

@Override
public void stop(final Throwable cause) {
publish(getContext(), new ChecksDetails.ChecksDetailsBuilder()
if (publish(getContext(), new ChecksDetails.ChecksDetailsBuilder()
.withName(step.getName())
.withStatus(ChecksStatus.COMPLETED)
.withConclusion(ChecksConclusion.CANCELED));
.withConclusion(ChecksConclusion.CANCELED))) {
getContext().onFailure(cause);
}
}

private void publish(final StepContext context, final ChecksDetails.ChecksDetailsBuilder builder) {
private boolean publish(final StepContext context, final ChecksDetails.ChecksDetailsBuilder builder) {
TaskListener listener = TaskListener.NULL;
try {
listener = fixNull(context.get(TaskListener.class), TaskListener.NULL);
Expand All @@ -134,20 +136,21 @@ private void publish(final StepContext context, final ChecksDetails.ChecksDetail
pluginLogger.log(msg);
SYSTEM_LOGGER.log(Level.WARNING, msg);
context.onFailure(new IllegalStateException(msg));
return;
return false;
}

if (run == null) {
String msg = "No Run found in the context.";
pluginLogger.log(msg);
SYSTEM_LOGGER.log(Level.WARNING, msg);
context.onFailure(new IllegalStateException(msg));
return;
return false;
}

ChecksPublisherFactory.fromRun(run, listener)
.publish(builder.withDetailsURL(DisplayURLProvider.get().getRunURL(run))
.build());
return true;
}

class WithChecksCallBack extends BodyExecutionCallback {
Expand Down

0 comments on commit 8215be6

Please sign in to comment.