Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 0b2d1b7

Browse files
CH38497 improve error handling (#30)
* added error handling for missing req files * updated error handling to print then throw * updated error message, moved try/catch to app.ts * updated changelog and version #
1 parent 65cb13c commit 0b2d1b7

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.2 (May 19, 2021)
4+
5+
Added error handling for missing configuration files
6+
37
## 1.1.1 (April 14, 2020)
48

59
Move `update-notifier` to dependencies and exclude from ncc build

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "awsx",
33
"description": "AWS CLI profile switcher with MFA support",
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"author": "Neo Financial Engineering <engineering@neofinancial.com>",
66
"license": "MIT",
77
"repository": {

src/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { STS } from 'aws-sdk';
66
import { promisify } from 'util';
77

88
import {
9+
configFileCheck,
910
backupConfig,
1011
initConfig,
1112
getProfileNames,
@@ -620,6 +621,12 @@ const status = async (): Promise<void> => {
620621
};
621622

622623
const awsx = (): void => {
624+
try {
625+
configFileCheck();
626+
} catch (error) {
627+
process.exit(1);
628+
}
629+
623630
updateNotifier({ pkg }).notify();
624631

625632
yargs

src/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ const AWSX_PROFILE_PATH = path.join(AWSX_HOME, 'profiles');
1212
const AWS_CREDENTIALS_PATH = path.join(AWS_HOME, 'credentials');
1313
const AWS_CONFIG_PATH = path.join(AWS_HOME, 'config');
1414

15+
const configFileCheck = (): void => {
16+
const hasCredentials = fs.existsSync(AWS_CREDENTIALS_PATH);
17+
const hasConfig = fs.existsSync(AWS_CONFIG_PATH);
18+
19+
!hasCredentials && console.error(`You are missing a required file at: ${AWS_CREDENTIALS_PATH}`);
20+
21+
!hasConfig && console.error(`You are missing a required file at: ${AWS_CONFIG_PATH}`);
22+
23+
if (!hasCredentials || !hasConfig) {
24+
console.error(
25+
`Run aws configure to fix this error: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html`
26+
);
27+
28+
throw new Error('Missing a required configuration file');
29+
}
30+
};
31+
1532
const copyFileIfExists = (sourcePath: string, destPath: string): void => {
1633
if (fs.existsSync(sourcePath)) {
1734
fs.copyFileSync(sourcePath, destPath);
@@ -244,6 +261,7 @@ const deleteAssumeRoleProfile = (profileName: string): void => {
244261
};
245262

246263
export {
264+
configFileCheck,
247265
backupConfig,
248266
initConfig,
249267
isMfaSessionStillValid,

0 commit comments

Comments
 (0)