@@ -6,14 +6,22 @@ import {
6
6
DataConverter ,
7
7
DefaultEncodedFailureAttributes ,
8
8
} from '@temporalio/common' ;
9
+ import { proxyActivities } from '@temporalio/workflow' ;
9
10
import { WorkflowFailedError } from '@temporalio/client' ;
10
11
import { decodeFromPayloadsAtIndex } from '@temporalio/common/lib/internal-non-workflow' ;
11
12
import { test , bundlerOptions , ByteSkewerPayloadCodec , Worker } from './helpers' ;
12
13
13
14
export const failureConverter = new DefaultFailureConverter ( { encodeCommonAttributes : true } ) ;
14
15
15
- export async function workflow ( ) : Promise < never > {
16
- throw ApplicationFailure . create ( { message : 'error message' } ) ;
16
+ class Activities {
17
+ public raise = async ( ) => {
18
+ throw ApplicationFailure . nonRetryable ( 'error message' ) ;
19
+ } ;
20
+ }
21
+
22
+ export async function workflow ( ) : Promise < void > {
23
+ const activities = proxyActivities < Activities > ( { startToCloseTimeout : '1m' } ) ;
24
+ await activities . raise ( ) ;
17
25
}
18
26
19
27
test ( 'Client and Worker use provided failureConverter' , async ( t ) => {
@@ -24,15 +32,10 @@ test('Client and Worker use provided failureConverter', async (t) => {
24
32
} ;
25
33
const env = await TestWorkflowEnvironment . createLocal ( { client : { dataConverter } } ) ;
26
34
try {
27
- const info = await env . connection . workflowService . getSystemInfo ( { } ) ;
28
- if ( ! info . capabilities ?. encodedFailureAttributes ) {
29
- t . pass ( 'Skipped test for lack of encodedFailureAttributes capability' ) ;
30
- return ;
31
- }
32
-
33
35
const taskQueue = 'test' ;
34
36
const worker = await Worker . create ( {
35
37
connection : env . nativeConnection ,
38
+ activities : new Activities ( ) ,
36
39
workflowsPath : __filename ,
37
40
taskQueue,
38
41
dataConverter,
@@ -42,19 +45,37 @@ test('Client and Worker use provided failureConverter', async (t) => {
42
45
// Run the workflow, expect error with message and stack trace
43
46
const handle = await env . client . workflow . start ( workflow , { taskQueue, workflowId : randomUUID ( ) } ) ;
44
47
const err = ( await worker . runUntil ( t . throwsAsync ( handle . result ( ) ) ) ) as WorkflowFailedError ;
45
- t . is ( err . cause ?. message , 'error message' ) ;
46
- t . true ( err . cause ?. stack ?. startsWith ( 'ApplicationFailure: error message\n' ) ) ;
48
+ t . is ( err . cause ?. message , 'Activity task failed' ) ;
49
+ t . is ( err . cause ?. cause ?. message , 'error message' ) ;
50
+ t . true ( err . cause ?. cause ?. stack ?. includes ( 'ApplicationFailure: error message\n' ) ) ;
47
51
48
52
// Verify failure was indeed encoded
49
53
const { events } = await handle . fetchHistory ( ) ;
50
- const payload = events ?. [ events . length - 1 ] . workflowExecutionFailedEventAttributes ?. failure ?. encodedAttributes ;
51
- const attrs = await decodeFromPayloadsAtIndex < DefaultEncodedFailureAttributes > (
52
- env . client . options . loadedDataConverter ,
53
- 0 ,
54
- payload ? [ payload ] : undefined
55
- ) ;
56
- t . is ( attrs . message , 'error message' ) ;
57
- t . true ( attrs . stack_trace . startsWith ( 'ApplicationFailure: error message\n' ) ) ;
54
+ const { failure } = events ?. [ events . length - 1 ] . workflowExecutionFailedEventAttributes ?? { } ;
55
+ {
56
+ const payload = failure ?. encodedAttributes ;
57
+ const attrs = await decodeFromPayloadsAtIndex < DefaultEncodedFailureAttributes > (
58
+ env . client . options . loadedDataConverter ,
59
+ 0 ,
60
+ payload ? [ payload ] : undefined
61
+ ) ;
62
+ t . is ( failure ?. message , 'Encoded failure' ) ;
63
+ t . is ( failure ?. stackTrace , '' ) ;
64
+ t . is ( attrs . message , 'Activity task failed' ) ;
65
+ t . is ( attrs . stack_trace , '' ) ;
66
+ }
67
+ {
68
+ const payload = failure ?. cause ?. encodedAttributes ;
69
+ const attrs = await decodeFromPayloadsAtIndex < DefaultEncodedFailureAttributes > (
70
+ env . client . options . loadedDataConverter ,
71
+ 0 ,
72
+ payload ? [ payload ] : undefined
73
+ ) ;
74
+ t . is ( failure ?. cause ?. message , 'Encoded failure' ) ;
75
+ t . is ( failure ?. stackTrace , '' ) ;
76
+ t . is ( attrs . message , 'error message' ) ;
77
+ t . true ( attrs . stack_trace . includes ( 'ApplicationFailure: error message\n' ) ) ;
78
+ }
58
79
} finally {
59
80
await env . teardown ( ) ;
60
81
}
0 commit comments