Try to get response body message and log entire error response in debug mode (#123)

This commit is contained in:
Nikola Jokic
2023-12-15 13:01:04 +01:00
committed by GitHub
parent 46c92fe43e
commit 0cce49705b
3 changed files with 32 additions and 6 deletions

View File

@@ -36,7 +36,15 @@ export async function runContainerStep(
core.debug(`Created secret ${secretName} for container job envs`)
const container = createContainerSpec(stepContainer, secretName, extension)
const job = await createJob(container, extension)
let job: k8s.V1Job
try {
job = await createJob(container, extension)
} catch (err) {
core.debug(`createJob failed: ${JSON.stringify(err)}`)
const message = (err as any)?.response?.body?.message || err
throw new Error(`failed to run script step: ${message}`)
}
if (!job.metadata?.name) {
throw new Error(
`Expected job ${JSON.stringify(
@@ -46,7 +54,15 @@ export async function runContainerStep(
}
core.debug(`Job created, waiting for pod to start: ${job.metadata?.name}`)
const podName = await getContainerJobPodName(job.metadata.name)
let podName: string
try {
podName = await getContainerJobPodName(job.metadata.name)
} catch (err) {
core.debug(`getContainerJobPodName failed: ${JSON.stringify(err)}`)
const message = (err as any)?.response?.body?.message || err
throw new Error(`failed to get container job pod name: ${message}`)
}
await waitForPodPhases(
podName,
new Set([PodPhase.COMPLETED, PodPhase.RUNNING, PodPhase.SUCCEEDED]),
@@ -58,6 +74,7 @@ export async function runContainerStep(
core.debug('Waiting for container job to complete')
await waitForJobToComplete(job.metadata.name)
// pod has failed so pull the status code from the container
const status = await getPodStatus(podName)
if (status?.phase === 'Succeeded') {