Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Strnadj committed Jul 14, 2022
1 parent bd6a123 commit 31ebd49
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
53 changes: 26 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -40614,7 +40613,7 @@ const main = async () => {
);
}
} catch (error) {
core.setFailed(error.message);
core.setFailed(error);
}
};

Expand Down
50 changes: 25 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 31ebd49

Please sign in to comment.