From 31ebd4931db7a3bde6126d96253bcdbd3866c66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Strn=C3=A1dek?= Date: Thu, 14 Jul 2022 11:04:14 +0200 Subject: [PATCH] Fix error handling --- dist/index.js | 53 +++++++++++++++++++++++++-------------------------- index.js | 50 ++++++++++++++++++++++++------------------------ 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3158806..e66bbe3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40536,38 +40536,37 @@ const main = async () => { required: false, }); - // Get network configuration from aws directly from describe services - core.debug("Getting information from service..."); - const info = await ecs.describeServices({ cluster, services: [service] }).promise(); + try { + // Get network configuration from aws directly from describe services + core.debug("Getting information from service..."); + const info = await ecs.describeServices({ cluster, services: [service] }).promise(); - if (!info) { - throw new Error(`Could not find service ${service} in cluster ${cluster}`); - } + if (!info || !info.services[0]) { + throw new Error(`Could not find service ${service} in cluster ${cluster}`); + } - if (!info.services[0].networkConfiguration) { - throw new Error(`Service ${service} in cluster ${cluster} does not have a network configuration`); - } + if (!info.services[0].networkConfiguration) { + throw new Error(`Service ${service} in cluster ${cluster} does not have a network configuration`); + } - const taskDefinition = info.services[0].taskDefinition; - const networkConfiguration = info.services[0].networkConfiguration; - core.setOutput("task-definition", taskDefinition); + const taskDefinition = info.services[0].taskDefinition; + const networkConfiguration = info.services[0].networkConfiguration; + core.setOutput("task-definition", taskDefinition); - const overrideContainerCommand = core.getMultilineInput( - "override-container-command", - { - required: false, - } - ); + const overrideContainerCommand = core.getMultilineInput( + "override-container-command", + { + required: false, + } + ); - const taskParams = { - taskDefinition, - cluster, - count: 1, - launchType: "FARGATE", - networkConfiguration, - }; + const taskParams = { + taskDefinition, + cluster, + launchType: "FARGATE", + networkConfiguration, + }; - try { if (overrideContainerCommand.length > 0 && !overrideContainer) { throw new Error( "override-container is required when override-container-command is set" @@ -40614,7 +40613,7 @@ const main = async () => { ); } } catch (error) { - core.setFailed(error.message); + core.setFailed(error); } }; diff --git a/index.js b/index.js index 451d1a6..fe3737e 100644 --- a/index.js +++ b/index.js @@ -11,37 +11,37 @@ const main = async () => { required: false, }); - // Get network configuration from aws directly from describe services - core.debug("Getting information from service..."); - const info = await ecs.describeServices({ cluster, services: [service] }).promise(); + try { + // Get network configuration from aws directly from describe services + core.debug("Getting information from service..."); + const info = await ecs.describeServices({ cluster, services: [service] }).promise(); - if (!info || !info.services[0]) { - throw new Error(`Could not find service ${service} in cluster ${cluster}`); - } + if (!info || !info.services[0]) { + throw new Error(`Could not find service ${service} in cluster ${cluster}`); + } - if (!info.services[0].networkConfiguration) { - throw new Error(`Service ${service} in cluster ${cluster} does not have a network configuration`); - } + if (!info.services[0].networkConfiguration) { + throw new Error(`Service ${service} in cluster ${cluster} does not have a network configuration`); + } - const taskDefinition = info.services[0].taskDefinition; - const networkConfiguration = info.services[0].networkConfiguration; - core.setOutput("task-definition", taskDefinition); + const taskDefinition = info.services[0].taskDefinition; + const networkConfiguration = info.services[0].networkConfiguration; + core.setOutput("task-definition", taskDefinition); - const overrideContainerCommand = core.getMultilineInput( - "override-container-command", - { - required: false, - } - ); + const overrideContainerCommand = core.getMultilineInput( + "override-container-command", + { + required: false, + } + ); - const taskParams = { - taskDefinition, - cluster, - launchType: "FARGATE", - networkConfiguration, - }; + const taskParams = { + taskDefinition, + cluster, + launchType: "FARGATE", + networkConfiguration, + }; - try { if (overrideContainerCommand.length > 0 && !overrideContainer) { throw new Error( "override-container is required when override-container-command is set"