Don't use JSON.stringify for errors (#19)

* better error handling

* remove unneeded catch

* Update index.ts
This commit is contained in:
Thomas Boop
2022-06-22 09:20:48 -04:00
committed by GitHub
parent 5c6995dba1
commit 4307828719
5 changed files with 27 additions and 31 deletions

View File

@@ -49,7 +49,7 @@ export async function prepareJob(
createdPod = await createPod(container, services, args.registry) createdPod = await createPod(container, services, args.registry)
} catch (err) { } catch (err) {
await prunePods() await prunePods()
throw new Error(`failed to create job pod: ${JSON.stringify(err)}`) throw new Error(`failed to create job pod: ${err}`)
} }
if (!createdPod?.metadata?.name) { if (!createdPod?.metadata?.name) {

View File

@@ -28,7 +28,7 @@ export async function runScriptStep(
JOB_CONTAINER_NAME JOB_CONTAINER_NAME
) )
} catch (err) { } catch (err) {
throw new Error(`failed to run script step: ${JSON.stringify(err)}`) throw new Error(`failed to run script step: ${err}`)
} finally { } finally {
fs.rmSync(runnerPath) fs.rmSync(runnerPath)
} }

View File

@@ -22,7 +22,7 @@ async function run(): Promise<void> {
throw new Error( throw new Error(
`The Service account needs the following permissions ${JSON.stringify( `The Service account needs the following permissions ${JSON.stringify(
requiredPermissions requiredPermissions
)} on the pod resource in the '${namespace}' namespace. Please contact your self hosted runner administrator.` )} on the pod resource in the '${namespace()}' namespace. Please contact your self hosted runner administrator.`
) )
} }
switch (command) { switch (command) {

View File

@@ -185,7 +185,6 @@ export async function execPodStep(
): Promise<void> { ): Promise<void> {
const exec = new k8s.Exec(kc) const exec = new k8s.Exec(kc)
await new Promise(async function (resolve, reject) { await new Promise(async function (resolve, reject) {
try {
await exec.exec( await exec.exec(
namespace(), namespace(),
podName, podName,
@@ -209,9 +208,6 @@ export async function execPodStep(
} }
} }
) )
} catch (error) {
reject(JSON.stringify(error))
}
}) })
} }
@@ -372,7 +368,7 @@ export async function getPodLogs(
}) })
logStream.on('error', err => { logStream.on('error', err => {
process.stderr.write(JSON.stringify(err)) process.stderr.write(err.message)
}) })
const r = await log.log(namespace(), podName, containerName, logStream, { const r = await log.log(namespace(), podName, containerName, logStream, {

View File

@@ -40,7 +40,7 @@ export class TestHelper {
await this.createTestVolume() await this.createTestVolume()
await this.createTestJobPod() await this.createTestJobPod()
} catch (e) { } catch (e) {
console.log(JSON.stringify(e)) console.log(e)
} }
} }