From f07ce5ce7389ea55bdbd0b04019d6695e07868c5 Mon Sep 17 00:00:00 2001 From: Thomas Bonnin <233326+TBonnin@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:15:17 +0200 Subject: [PATCH] chore: log error in handlePayloadTooBigError (#2576) I noticed the following error this morning when a runner send the output of a task back to jobs: Error: PUT /tasks/:taskId: status=500, response={"error":{"code":"server_error","message":"Cannot read properties of undefined (reading 'code')"}} It looks like setting the task as failed/succeed fails but the error doesn't have the shape we expect. Adding a try/catch to log the error and let the execution continue and log the setSucceed/setFailed error ## Issue ticket number and link ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] I added observability, otherwise the reason is: - [ ] I added analytics, otherwise the reason is: --- .../jobs/lib/execution/operations/output.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/jobs/lib/execution/operations/output.ts b/packages/jobs/lib/execution/operations/output.ts index 740dabd0e9..8cb6abf03a 100644 --- a/packages/jobs/lib/execution/operations/output.ts +++ b/packages/jobs/lib/execution/operations/output.ts @@ -75,16 +75,20 @@ export async function handleError({ } async function handlePayloadTooBigError({ taskId, error, nangoProps }: { taskId: string; error: ClientError; nangoProps: NangoProps }): Promise { - if ( - error.payload && - typeof error.payload === 'object' && - 'response' in error.payload && - error.payload['response'] && - typeof error.payload['response'] === 'object' - ) { - const res = error.payload['response'] as unknown as ApiError; - if (res.error.code === 'payload_too_big') { - await orchestratorClient.failed({ taskId, error: new NangoError('script_output_too_big', { syncId: nangoProps.syncId }) }); + try { + if ( + error.payload && + typeof error.payload === 'object' && + 'response' in error.payload && + error.payload['response'] && + typeof error.payload['response'] === 'object' + ) { + const res = error.payload['response'] as unknown as ApiError; + if (res.error.code === 'payload_too_big') { + await orchestratorClient.failed({ taskId, error: new NangoError('script_output_too_big', { syncId: nangoProps.syncId }) }); + } } + } catch (err: unknown) { + logger.error(`failed to handle payload too big error for task ${taskId}`, err); } }