Skip to content

Commit 6e45cba

Browse files
authored
Merge pull request #204 from gbhat618/import-SynchronousResumeNotSupportedException-message
Report the failed step name in SynchronousResumeNotSupportedException
2 parents bbb6ce4 + 52c6092 commit 6e45cba

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/main/java/org/jenkinsci/plugins/workflow/steps/AbstractSynchronousNonBlockingStepExecution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public void stop(Throwable cause) throws Exception {
6767

6868
@Override
6969
public void onResume() {
70-
getContext().onFailure(new SynchronousResumeNotSupportedException());
70+
var context = getContext();
71+
context.onFailure(new SynchronousResumeNotSupportedException(context));
7172
}
7273

7374
@Override public @NonNull String getStatus() {

src/main/java/org/jenkinsci/plugins/workflow/steps/GeneralNonBlockingStepExecution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public void stop(Throwable cause) throws Exception {
104104
@Override
105105
public void onResume() {
106106
if (threadName != null) {
107-
getContext().onFailure(new SynchronousResumeNotSupportedException());
107+
var context = getContext();
108+
context.onFailure(new SynchronousResumeNotSupportedException(context));
108109
}
109110
}
110111

src/main/java/org/jenkinsci/plugins/workflow/steps/SynchronousNonBlockingStepExecution.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import hudson.util.ClassLoaderSanityThreadFactory;
66
import hudson.util.DaemonThreadFactory;
77
import hudson.util.NamingThreadFactory;
8+
9+
import java.io.IOException;
810
import java.util.concurrent.ExecutorService;
911
import java.util.concurrent.Executors;
1012
import java.util.concurrent.Future;
@@ -72,7 +74,8 @@ public void stop(Throwable cause) throws Exception {
7274

7375
@Override
7476
public void onResume() {
75-
getContext().onFailure(new SynchronousResumeNotSupportedException());
77+
var context = getContext();
78+
context.onFailure(new SynchronousResumeNotSupportedException(context));
7679
}
7780

7881
@Override public @NonNull String getStatus() {

src/main/java/org/jenkinsci/plugins/workflow/steps/SynchronousResumeNotSupportedException.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
package org.jenkinsci.plugins.workflow.steps;
2626

27+
import java.io.IOException;
28+
import java.util.logging.Level;
29+
import java.util.logging.Logger;
30+
2731
/**
2832
* May be reported from {@link StepExecution#onResume} when the step does not support resumption.
2933
* Thrown by default from {@link SynchronousNonBlockingStepExecution},
@@ -33,8 +37,32 @@
3337
*/
3438
public class SynchronousResumeNotSupportedException extends Exception {
3539

40+
private static final Logger LOGGER = Logger.getLogger(SynchronousResumeNotSupportedException.class.getName());
41+
42+
/**
43+
* @deprecated Use {@link #SynchronousResumeNotSupportedException(StepContext)} instead.
44+
*/
45+
@Deprecated
3646
public SynchronousResumeNotSupportedException() {
3747
super("Resume after a restart not supported for non-blocking synchronous steps");
3848
}
3949

50+
public SynchronousResumeNotSupportedException(StepContext context) {
51+
super(String.format("""
52+
The Pipeline step `%s` cannot be resumed after a controller restart. \
53+
In Scripted syntax, you may wrap its containing `node` block within `retry(conditions: [nonresumable()], count: 2) {...}`, \
54+
or, in Declarative syntax, use the `retries` option to an `agent` directive to allow the stage to be retried.""",
55+
getStepDisplayFunctionName(context))
56+
);
57+
}
58+
59+
private static String getStepDisplayFunctionName(StepContext stepContext) {
60+
StepDescriptor descriptor = null;
61+
try {
62+
descriptor = stepContext.get(StepDescriptor.class);
63+
} catch (IOException | InterruptedException e) {
64+
LOGGER.log(Level.FINE, "Failed to get descriptor: ", e);
65+
}
66+
return descriptor != null ? descriptor.getFunctionName() : "?";
67+
}
4068
}

0 commit comments

Comments
 (0)