From ae432db5122c8e9493357b7aeb015481cdd49371 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 23 Jan 2023 12:46:47 +0100 Subject: [PATCH] docker and k8s: read from stdin inside try catch block (#49) There might be situation where reading from standard input fails. In that case, we should encapsulate that exception within the try catch block to avoid unhandeled Promise rejection exception and provide more information about the error --- packages/docker/src/index.ts | 13 ++++++------- packages/k8s/src/index.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/docker/src/index.ts b/packages/docker/src/index.ts index 3419c4f..278d951 100644 --- a/packages/docker/src/index.ts +++ b/packages/docker/src/index.ts @@ -16,15 +16,14 @@ import { import { checkEnvironment } from './utils' async function run(): Promise { - const input = await getInputFromStdin() - - const args = input['args'] - const command = input['command'] - const responseFile = input['responseFile'] - const state = input['state'] - try { checkEnvironment() + const input = await getInputFromStdin() + + const args = input['args'] + const command = input['command'] + const responseFile = input['responseFile'] + const state = input['state'] switch (command) { case Command.PrepareJob: await prepareJob(args as PrepareJobArgs, responseFile) diff --git a/packages/k8s/src/index.ts b/packages/k8s/src/index.ts index d58167b..452d1e7 100644 --- a/packages/k8s/src/index.ts +++ b/packages/k8s/src/index.ts @@ -9,15 +9,14 @@ import { import { isAuthPermissionsOK, namespace, requiredPermissions } from './k8s' async function run(): Promise { - const input = await getInputFromStdin() - - const args = input['args'] - const command = input['command'] - const responseFile = input['responseFile'] - const state = input['state'] - let exitCode = 0 try { + const input = await getInputFromStdin() + + const args = input['args'] + const command = input['command'] + const responseFile = input['responseFile'] + const state = input['state'] if (!(await isAuthPermissionsOK())) { throw new Error( `The Service account needs the following permissions ${JSON.stringify(