Skip to content

Commit ffffe49

Browse files
authored
Coerce fork event version (#713)
* coerce fork event version * log parsing failurs * move the ignore statement
1 parent 8384988 commit ffffe49

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
import { ZodError } from 'zod';
2+
3+
import logger from '@/utils/logger';
14
import { allWorkflowEvents } from '@/views/workflow-history/__fixtures__/all-workflow-event-types';
25

36
import formatWorkflowHistoryEvent from '..';
47

8+
jest.mock('@/utils/logger');
9+
510
describe('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
});

src/utils/data-formatters/format-workflow-history-event/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { HistoryEvent } from '@/__generated__/proto-ts/uber/cadence/api/v1/HistoryEvent';
2+
import logger from '@/utils/logger';
23

34
import {
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;

src/utils/data-formatters/schema/history-event-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}),

0 commit comments

Comments
 (0)