Skip to content

Commit c9b754a

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>
1 parent dd6c143 commit c9b754a

File tree

8 files changed

+114
-7
lines changed

8 files changed

+114
-7
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) {
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
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-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 == 503 }
16+
do:
17+
- handleError:
18+
set:
19+
recovered: true

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ do:
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

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

Lines changed: 1 addition & 1 deletion
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-not-match-when
55
version: '0.1.0'
66
do:
77
- attemptTask:

0 commit comments

Comments
 (0)