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
This commit is contained in:
Nikola Jokic
2023-01-23 12:46:47 +01:00
committed by GitHub
parent 4448b61e00
commit ae432db512
2 changed files with 12 additions and 14 deletions

View File

@@ -16,15 +16,14 @@ import {
import { checkEnvironment } from './utils' import { checkEnvironment } from './utils'
async function run(): Promise<void> { async function run(): Promise<void> {
const input = await getInputFromStdin()
const args = input['args']
const command = input['command']
const responseFile = input['responseFile']
const state = input['state']
try { try {
checkEnvironment() checkEnvironment()
const input = await getInputFromStdin()
const args = input['args']
const command = input['command']
const responseFile = input['responseFile']
const state = input['state']
switch (command) { switch (command) {
case Command.PrepareJob: case Command.PrepareJob:
await prepareJob(args as PrepareJobArgs, responseFile) await prepareJob(args as PrepareJobArgs, responseFile)

View File

@@ -9,15 +9,14 @@ import {
import { isAuthPermissionsOK, namespace, requiredPermissions } from './k8s' import { isAuthPermissionsOK, namespace, requiredPermissions } from './k8s'
async function run(): Promise<void> { async function run(): Promise<void> {
const input = await getInputFromStdin()
const args = input['args']
const command = input['command']
const responseFile = input['responseFile']
const state = input['state']
let exitCode = 0 let exitCode = 0
try { try {
const input = await getInputFromStdin()
const args = input['args']
const command = input['command']
const responseFile = input['responseFile']
const state = input['state']
if (!(await isAuthPermissionsOK())) { if (!(await isAuthPermissionsOK())) {
throw new Error( throw new Error(
`The Service account needs the following permissions ${JSON.stringify( `The Service account needs the following permissions ${JSON.stringify(