I'm trying to understand why a Promise rejection exception I've encountered is not being handled by my initial try/catch in the following code (full code is in this branch)
In this particular error, nodeCf.deploy
is being called in index.js.
The error is happening because I should be using this.deployName
, not stack.deployName
in my console.log statement.
The thing I don't understand is why this is considered an unhandle Promise rejection. Shouldn't the try/catch I have in the initial call to nodeCf.deploy catch this?
// index.js:
switch (args.action) {
case 'deploy':
try {
await nodeCf.deploy(stacks, envVars);
} catch (e) {
console.log(`deployment failed: `, e);
process.exit(1);
}
break;
< ... >
// nodeCf module:
async deploy(stacks, envVars) {
var stackOutputs = {};
await Promise.each(stacks, async(stack) => {
stackOutputs[stack.name] = await stack.deploy(envVars,
stackOutputs).outputs;
});
}
// stack.deploy:
async deploy(envVars, stackOutputs) {
this.load(envVars, stackOutputs);
await ensureBucket(this.infraBucket);
const s3Resp = await this.uploadTemplate()
const stackResp = await ensureAwsCfStack({
StackName: this.deployName,
Parameters: this.parameters,
Tags: this.tags,
TemplateURL: s3Resp.Location,
Capabilities: [ 'CAPABILITY_IAM',
'CAPABILITY_NAMED_IAM' ]
});
this.outputs = _.map(stackResp.Outputs, (it) =>
_(it).pick(['OutputKey', 'OutputValue'])
.toPairs()
.unzip()
.tail()
.fromPairs()
.value());
console.log(`deployed ${stack.deployName}`); // 'stack' is causing exception
return this;
}
via rumdrums
No comments:
Post a Comment