Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Dec 7, 2023
1 parent 5d6f84d commit a005dd7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "samp-cli",
"version": "1.0.66",
"version": "1.0.67",
"description": "CLI tool for extended productivity with AWS Serverless Application Model (SAM)",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/commands/stepfunctions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
.option("--region [region]", "The AWS region to use. Falls back on AWS_REGION environment variable if not specified")

.action(async (cmd, opts) => {
try {
if (cmd === "init") {
opts.logicalId = await inputUtil.text("Name of state machine resource", "StateMachine");
opts.aslFile = await inputUtil.text("Path to output ASL definition file", "statemachine.yaml");
Expand All @@ -27,5 +28,12 @@ program
} else {
console.log("Unknown command. Valid commands are: init, sync, test-state");
}
} catch (e) {
console.log("\n" + e.message + "\nTo see the full stack trace, set environment variable SAMP_DEBUG=1 and run the command again.");
if (process.env.SAMP_DEBUG) {
console.log(e.stack);
}
process.exit(1);
}
return;
});
20 changes: 18 additions & 2 deletions src/commands/stepfunctions/test-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,25 @@ const { Spinner } = require('cli-spinner');

const os = require('os');
let clientParams;
async function run(cmd) {
async function run(cmd) {
const config = await samConfigParser.parse();
const credentials = await fromSSO({ profile: cmd.profile || config.profile || 'default' });

if (!cmd.stackName && !config.stack_name) {
console.log("No stack name found. Use --stack-name or set stack_name in samconfig.toml");
process.exit(1);
}

if (!cmd.region && !config.region) {
console.log("No region found. Use --region or set region in samconfig.toml");
process.exit(1);
}

let credentials;
try {
credentials = await fromSSO({ profile: cmd.profile || config.profile || 'default' });
} catch (e) {
}

clientParams = { credentials, region: cmd.region || config.region }
const sfnClient = new SFNClient(clientParams);
const cloudFormation = new CloudFormationClient(clientParams);
Expand Down
6 changes: 3 additions & 3 deletions src/shared/samConfigParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function parse() {

const envConfig = config[configEnv].deploy.parameters;
envConfig.configEnv = process.env.configEnv || 'default';
envConfig.stack_name = envConfig.stack_name || config[configEnv].global.parameters.stack_name
envConfig.region = envConfig.region || config[configEnv].global.parameters.region || process.env.AWS_REGION;
envConfig.profile = envConfig.profile || config[configEnv].global?.parameters.profile || process.env.AWS_PROFILE || 'default';
envConfig.stack_name = envConfig.stack_name || config[configEnv].global?.parameters?.stack_name
envConfig.region = envConfig.region || config[configEnv].global?.parameters?.region || process.env.AWS_REGION;
envConfig.profile = envConfig.profile || config[configEnv].global?.parameters?.profile || process.env.AWS_PROFILE || 'default';
return envConfig;
}

Expand Down

0 comments on commit a005dd7

Please sign in to comment.