Skip to content

Commit 52c6092

Browse files
committed
remove additional util - rather find function name within the exception constructor
1 parent daeaba1 commit 52c6092

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
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(StepExecutionUtil.getStepDisplayFunctionName(this)));
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(StepExecutionUtil.getStepDisplayFunctionName(this)));
107+
var context = getContext();
108+
context.onFailure(new SynchronousResumeNotSupportedException(context));
108109
}
109110
}
110111

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

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

7575
@Override
7676
public void onResume() {
77-
getContext().onFailure(new SynchronousResumeNotSupportedException(StepExecutionUtil.getStepDisplayFunctionName(this)));
77+
var context = getContext();
78+
context.onFailure(new SynchronousResumeNotSupportedException(context));
7879
}
7980

8081
@Override public @NonNull String getStatus() {

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

Lines changed: 19 additions & 3 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,20 +37,32 @@
3337
*/
3438
public class SynchronousResumeNotSupportedException extends Exception {
3539

40+
private static final Logger LOGGER = Logger.getLogger(SynchronousResumeNotSupportedException.class.getName());
41+
3642
/**
37-
* @deprecated Use {@link #SynchronousResumeNotSupportedException(String)} instead.
43+
* @deprecated Use {@link #SynchronousResumeNotSupportedException(StepContext)} instead.
3844
*/
3945
@Deprecated
4046
public SynchronousResumeNotSupportedException() {
4147
super("Resume after a restart not supported for non-blocking synchronous steps");
4248
}
4349

44-
public SynchronousResumeNotSupportedException(String stepDisplayFunctionName) {
50+
public SynchronousResumeNotSupportedException(StepContext context) {
4551
super(String.format("""
4652
The Pipeline step `%s` cannot be resumed after a controller restart. \
4753
In Scripted syntax, you may wrap its containing `node` block within `retry(conditions: [nonresumable()], count: 2) {...}`, \
4854
or, in Declarative syntax, use the `retries` option to an `agent` directive to allow the stage to be retried.""",
49-
stepDisplayFunctionName)
55+
getStepDisplayFunctionName(context))
5056
);
5157
}
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+
}
5268
}

0 commit comments

Comments
 (0)