Skip to content

Commit

Permalink
chore: add try/catch to execPodStep (#9)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nielstenboom authored Dec 4, 2023
1 parent 338a35b commit a775201
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
50 changes: 27 additions & 23 deletions packages/k8s/src/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,34 @@ export async function execPodStep(
): Promise<void> {
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}`)
}
})
}

Expand Down

0 comments on commit a775201

Please sign in to comment.