From a775201731adc0dfce609d0a02ea557fff20febc Mon Sep 17 00:00:00 2001 From: Niels ten Boom Date: Mon, 4 Dec 2023 09:27:51 +0100 Subject: [PATCH] chore: add try/catch to execPodStep (#9) * move try catch higher * formatting * earlier linting * screw the linter * try this * empty commit for ci * this should do it? * add bump to package.json --- package.json | 2 +- packages/k8s/src/k8s/index.ts | 50 +++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 23ed927d..53b08d29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hooks", - "version": "0.3.10", + "version": "0.3.11", "description": "Three projects are included - k8s: a kubernetes hook implementation that spins up pods dynamically to run a job - docker: A hook implementation of the runner's docker implementation - A hook lib, which contains shared typescript definitions and utilities that the other packages consume", "main": "", "directories": { diff --git a/packages/k8s/src/k8s/index.ts b/packages/k8s/src/k8s/index.ts index 3a00d76a..f8f0d7b1 100644 --- a/packages/k8s/src/k8s/index.ts +++ b/packages/k8s/src/k8s/index.ts @@ -222,30 +222,34 @@ export async function execPodStep( ): Promise { const exec = new k8s.Exec(kc) await new Promise(async function (resolve, reject) { - await exec.exec( - namespace(), - podName, - containerName, - command, - process.stdout, - process.stderr, - stdin ?? null, - false /* tty */, - resp => { - // kube.exec returns an error if exit code is not 0, but we can't actually get the exit code - if (resp.status === 'Success') { - resolve(resp.code) - } else { - core.debug( - JSON.stringify({ - message: resp?.message, - details: resp?.details - }) - ) - reject(resp?.message) + try { + await exec.exec( + namespace(), + podName, + containerName, + command, + process.stdout, + process.stderr, + stdin ?? null, + false /* tty */, + resp => { + // kube.exec returns an error if exit code is not 0, but we can't actually get the exit code + if (resp.status === 'Success') { + resolve(resp.code) + } else { + core.debug( + JSON.stringify({ + message: resp?.message, + details: resp?.details + }) + ) + reject(resp?.message) + } } - } - ) + ) + } catch (error) { + core.error(`Failed to exec pod step: ${error}`) + } }) }