File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
src/utils/data-formatters
format-workflow-history-event Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1+ import { ZodError } from 'zod' ;
2+
3+ import logger from '@/utils/logger' ;
14import { allWorkflowEvents } from '@/views/workflow-history/__fixtures__/all-workflow-event-types' ;
25
36import formatWorkflowHistoryEvent from '..' ;
47
8+ jest . mock ( '@/utils/logger' ) ;
9+
510describe ( 'formatWorkflowHistoryEvent' , ( ) => {
611 allWorkflowEvents . forEach ( ( event ) => {
712 it ( `should format workflow ${ event . attributes } to match snapshot` , ( ) => {
813 expect ( formatWorkflowHistoryEvent ( event ) ) . toMatchSnapshot ( ) ;
914 } ) ;
1015 } ) ;
16+ it ( `should log error if parsing failed` , ( ) => {
17+ expect (
18+ //@ts -expect-error pass event with missing fields
19+ formatWorkflowHistoryEvent ( {
20+ attributes : 'workflowExecutionStartedEventAttributes' ,
21+ } )
22+ ) . toBe ( null ) ;
23+ expect ( logger . warn ) . toHaveBeenCalledWith (
24+ { cause : expect . any ( ZodError ) } ,
25+ 'Failed to format workflow event'
26+ ) ;
27+ } ) ;
1128} ) ;
Original file line number Diff line number Diff line change 11import type { HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent' ;
2+ import logger from '@/utils/logger' ;
23
34import {
45 type FormattedHistoryEvent ,
@@ -10,7 +11,11 @@ export default function formatWorkflowHistoryEvent(
1011) : FormattedHistoryEvent | null {
1112 const schema = getFormatHistoryEventSchema ( event ) ;
1213 if ( schema ) {
13- const { data } = schema . safeParse ( event ) ;
14+ const { data, error } = schema . safeParse ( event ) ;
15+ if ( error ) {
16+ logger . warn ( { cause : error } , 'Failed to format workflow event' ) ;
17+ return null ;
18+ }
1419 return data ?? null ;
1520 }
1621 return null ;
Original file line number Diff line number Diff line change @@ -315,7 +315,7 @@ export const decisionTaskFailedEventSchema = historyEventBaseSchema.extend({
315315 identity : z . string ( ) ,
316316 baseRunId : z . string ( ) ,
317317 newRunId : z . string ( ) ,
318- forkEventVersion : z . string ( ) ,
318+ forkEventVersion : z . coerce . string ( ) ,
319319 binaryChecksum : z . string ( ) ,
320320 requestId : z . string ( ) ,
321321 } ) ,
You can’t perform that action at this time.
0 commit comments