Skip to content

Commit c8083bd

Browse files
fjtiradoCopilot
andcommitted
[Fix #1198] Copilot comments
Signed-off-by: fjtirado <ftirados@redhat.com> Update impl/test/src/test/resources/workflows-samples/try-catch-not-match-details.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update impl/test/src/test/resources/workflows-samples/try-catch-match-status.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update impl/test/src/test/resources/workflows-samples/try-catch-match-details.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update impl/test/src/test/java/io/serverlessworkflow/impl/test/RetryTimeoutTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update impl/test/src/test/resources/workflows-samples/try-catch-error-variable.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dd6c143 commit c8083bd

File tree

9 files changed

+132
-25
lines changed

9 files changed

+132
-25
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/TryExecutor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,16 @@ private CompletableFuture<WorkflowModel> handleException(
171171
WorkflowException exception = (WorkflowException) e;
172172
CompletableFuture<WorkflowModel> completable =
173173
CompletableFuture.completedFuture(taskContext.rawOutput());
174-
if (errorFilter.map(f -> f.test(exception.getWorkflowError())).orElse(true)
174+
WorkflowError error = exception.getWorkflowError();
175+
if (errorFilter.map(f -> f.test(error)).orElse(true)
175176
&& WorkflowUtils.whenExceptTest(
176-
whenFilter, exceptFilter, workflow, taskContext, taskContext.rawOutput())) {
177+
whenFilter,
178+
exceptFilter,
179+
workflow,
180+
taskContext,
181+
workflow.definition().application().modelFactory().fromAny(error))) {
177182
if (errorVariable != null) {
178-
taskContext.variables().put(errorVariable, exception.getWorkflowError());
183+
taskContext.variables().put(errorVariable, error);
179184
}
180185
if (catchTaskExecutor.isPresent()) {
181186
completable =

impl/test/src/test/java/io/serverlessworkflow/impl/test/RetryTimeoutTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,27 @@ void testTimeout() throws IOException {
125125
@ParameterizedTest
126126
@ValueSource(
127127
strings = {
128-
"workflows-samples/try-catch-not-match.yaml",
128+
"workflows-samples/try-catch-match-when.yaml",
129+
"workflows-samples/try-catch-match-status.yaml",
130+
"workflows-samples/try-catch-match-details.yaml"
131+
})
132+
void testDoesMatch(String path) throws IOException {
133+
assertThat(
134+
app.workflowDefinition(readWorkflowFromClasspath(path))
135+
.instance(Map.of())
136+
.start()
137+
.join()
138+
.asMap()
139+
.map(m -> m.get("recovered"))
140+
.orElseThrow())
141+
.isEqualTo(true);
142+
}
143+
144+
@ParameterizedTest
145+
@ValueSource(
146+
strings = {
147+
"workflows-samples/try-catch-not-match-when.yaml",
148+
"workflows-samples/try-catch-not-match-status.yaml",
129149
"workflows-samples/try-catch-not-match-details.yaml"
130150
})
131151
void testDoesNotMatch(String path) {

impl/test/src/test/resources/workflows-samples/try-catch-error-variable.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ document:
66
do:
77
- attemptTask:
88
try:
9-
- failingTask:
10-
raise:
11-
error:
12-
type: https://example.com/errors/transient
13-
detail: Javierito was here!
14-
status: 503
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/transient
13+
detail: Javierito was here!
14+
status: 503
1515
catch:
16-
as: caughtError
17-
do:
18-
- handleError:
19-
set:
20-
errorMessage: ${$caughtError.details}
16+
as: caughtError
17+
do:
18+
- handleError:
19+
set:
20+
errorMessage: ${$caughtError.details}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: test
4+
name: try-catch-match-details
5+
version: '0.1.0'
6+
do:
7+
- attemptTask:
8+
try:
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/transient
13+
status: 503
14+
detail: Enforcement Failure - invalid email
15+
catch:
16+
errors:
17+
with:
18+
type: https://example.com/errors/transient
19+
status: 503
20+
details: Enforcement Failure - invalid email
21+
do:
22+
- handleError:
23+
set:
24+
recovered: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: test
4+
name: try-catch-match-status
5+
version: '0.1.0'
6+
do:
7+
- attemptTask:
8+
try:
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/transient
13+
status: 503
14+
catch:
15+
errors:
16+
with:
17+
type: https://example.com/errors/transient
18+
status: 503
19+
do:
20+
- handleError:
21+
set:
22+
recovered: true

impl/test/src/test/resources/workflows-samples/try-catch-not-match.yaml renamed to impl/test/src/test/resources/workflows-samples/try-catch-match-when.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
document:
22
dsl: '1.0.0'
33
namespace: test
4-
name: try-catch-not-match
4+
name: try-catch-match-when
55
version: '0.1.0'
66
do:
77
- attemptTask:
@@ -12,7 +12,7 @@ do:
1212
type: https://example.com/errors/transient
1313
status: 503
1414
catch:
15-
when: ${ .status == 400 }
15+
when: ${ .status == 503 }
1616
do:
1717
- handleError:
1818
set:

impl/test/src/test/resources/workflows-samples/try-catch-not-match-details.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ document:
66
do:
77
- attemptTask:
88
try:
9-
- failingTask:
10-
raise:
11-
error:
12-
type: https://example.com/errors/security
13-
status: 403
14-
detail: Enforcement Failure - invalid email
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/security
13+
status: 403
14+
detail: Enforcement Failure - invalid email
1515
catch:
1616
errors:
1717
with:
1818
type: https://example.com/errors/security
1919
status: 403
20-
details: User not found in tenant catalog
21-
20+
details: User not found in tenant catalog
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: test
4+
name: try-catch-not-match-status
5+
version: '0.1.0'
6+
do:
7+
- attemptTask:
8+
try:
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/transient
13+
status: 503
14+
catch:
15+
errors:
16+
with:
17+
type: https://example.com/errors/transient
18+
status: 403
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
document:
2+
dsl: '1.0.0'
3+
namespace: test
4+
name: try-catch-not-match-when
5+
version: '0.1.0'
6+
do:
7+
- attemptTask:
8+
try:
9+
- failingTask:
10+
raise:
11+
error:
12+
type: https://example.com/errors/transient
13+
status: 503
14+
catch:
15+
when: ${ .status == 400 }
16+
do:
17+
- handleError:
18+
set:
19+
recovered: true

0 commit comments

Comments
 (0)