Skip to content

Commit bced653

Browse files
committed
refactor(k8s): consolidate the 4 actions#341 throw sites via formatError()
actions#341 (merged 2026-06-03) replaced `JSON.stringify(error)` with `error instanceof Error ? error.message : String(error)` at four throw sites in k8s/index.ts. Now that `formatError()` ships in k8s/utils.ts (introduced in the same PR as this commit), use it instead — a strict superset that additionally: - extracts `response.body.message` (and `reason`) from @kubernetes/client-node API errors at `waitForPodPhases` and `waitForJobToComplete`, which currently surface a generic "HTTP request failed" instead of the actual K8s server message; - never throws on circular references (the original actions#329 bug). Also drops the `.stack ?? .message` branch in formatError() and returns just `.message` for Error instances. This keeps the format predictable (no stack trace dumped into user-visible CI errors) and lets actions#341's `error-serialization-test.ts` continue to pass unchanged.
1 parent c8d19d5 commit bced653

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

packages/k8s/src/k8s/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '../hooks/constants'
1515
import {
1616
PodPhase,
17+
formatError,
1718
mergePodSpecWithOptions,
1819
mergeObjectMeta,
1920
fixArgs,
@@ -517,7 +518,7 @@ export async function execCpToPod(
517518
attempt++
518519
if (attempt >= 30) {
519520
throw new Error(
520-
`cpToPod failed after ${attempt} attempts: ${error instanceof Error ? error.message : String(error)}`
521+
`cpToPod failed after ${attempt} attempts: ${formatError(error)}`
521522
)
522523
}
523524
await sleep(1000)
@@ -614,7 +615,7 @@ export async function execCpFromPod(
614615
attempt++
615616
if (attempt >= 30) {
616617
throw new Error(
617-
`execCpFromPod failed after ${attempt} attempts: ${error instanceof Error ? error.message : String(error)}`
618+
`execCpFromPod failed after ${attempt} attempts: ${formatError(error)}`
618619
)
619620
}
620621
await sleep(1000)
@@ -661,7 +662,7 @@ export async function waitForJobToComplete(jobName: string): Promise<void> {
661662
return
662663
}
663664
} catch (error) {
664-
throw new Error(`job ${jobName} has failed: ${error instanceof Error ? error.message : String(error)}`)
665+
throw new Error(`job ${jobName} has failed: ${formatError(error)}`)
665666
}
666667
await backOffManager.backOff()
667668
}
@@ -784,7 +785,7 @@ export async function waitForPodPhases(
784785
}
785786
} catch (error) {
786787
throw new Error(
787-
`Pod ${podName} is unhealthy with phase status ${phase}: ${error instanceof Error ? error.message : String(error)}`
788+
`Pod ${podName} is unhealthy with phase status ${phase}: ${formatError(error)}`
788789
)
789790
}
790791
}

packages/k8s/src/k8s/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function formatError(err: unknown): string {
331331
}
332332

333333
if (err instanceof Error) {
334-
return err.stack ?? err.message
334+
return err.message
335335
}
336336

337337
// Primitives serialise more readably via String() than JSON.stringify

0 commit comments

Comments
 (0)