Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit a40e151

Browse files
authored
[FEATURE] Add specific error code for spk init command (#524)
* [FEATURE] Add specific error code for spk init command * correct gramatical error
1 parent 8e66cc3 commit a40e151

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/commands/init.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
saveConfiguration,
1111
} from "../config";
1212
import { build as buildCmd, exit as exitCmd } from "../lib/commandBuilder";
13+
import { build as buildError, log as logError } from "../lib/errorBuilder";
14+
import { errorStatusCode } from "../lib/errorStatusCode";
1315
import * as promptBuilder from "../lib/promptBuilder";
1416
import { deepClone } from "../lib/util";
1517
import { hasValue } from "../lib/validator";
@@ -93,8 +95,9 @@ export const validatePersonalAccessToken = async (
9395
azure: ConfigYaml["azure_devops"]
9496
): Promise<boolean> => {
9597
if (!azure || !azure.org || !azure.project || !azure.access_token) {
96-
throw Error(
97-
"Unable to validate personal access token because organization, project or access token information were missing"
98+
throw buildError(
99+
errorStatusCode.ENV_SETTING_ERR,
100+
"init_cmd_unable_validate_pat"
98101
);
99102
}
100103
try {
@@ -109,6 +112,7 @@ export const validatePersonalAccessToken = async (
109112
);
110113
return res.status === 200;
111114
} catch (_) {
115+
// command does not terminate if pat cannot be verified.
112116
return false;
113117
}
114118
};
@@ -194,13 +198,12 @@ export const execute = async (
194198
): Promise<void> => {
195199
try {
196200
if (!hasValue(opts.file) && !opts.interactive) {
197-
throw new Error(
198-
"File that stores configuration is not provided and interactive mode is not turn on"
199-
);
201+
throw buildError(errorStatusCode.VALIDATION_ERR, "init_cmd_missing_opts");
200202
}
201203
if (hasValue(opts.file) && opts.interactive) {
202-
throw new Error(
203-
"Not supported option while configuration file is provided and interactive mode is turn on"
204+
throw buildError(
205+
errorStatusCode.VALIDATION_ERR,
206+
"init_cmd_both_opts_err"
204207
);
205208
}
206209

@@ -212,8 +215,7 @@ export const execute = async (
212215

213216
await exitFn(0);
214217
} catch (err) {
215-
logger.error(`Error occurred while initializing`);
216-
logger.error(err);
218+
logError(buildError(errorStatusCode.CMD_EXE_ERR, "init_cmd_failed", err));
217219
await exitFn(1);
218220
}
219221
};

src/lib/i18n.json

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"storageKeVaultName": "Enter key vault name (have the value as empty and hit enter key to skip)"
1717
},
1818
"errors": {
19+
"init_cmd_failed": "Init command was not successfully executed.",
20+
"init_cmd_unable_validate_pat": "Could not validate personal access token because organization, project or access token information were missing. Provide them in config.yaml.",
21+
"init_cmd_missing_opts": "Could not execute this command because file that stores configuration was not provided and interactive mode was not set. Provide file name or enable interactive mode.",
22+
"init_cmd_both_opts_err": "Could not execute this command because file that stores configuration was provided and interactive mode was set. Provide file name or enable interactive mode.",
23+
1924
"setup-cmd-failed": "Setup command was not successfully executed.",
2025
"setup-cmd-prompt-err-no-subscriptions": "No subscriptions found.",
2126
"setup-cmd-prompt-err-subscription-missing": "Subscription Identifier was missing.",

0 commit comments

Comments
 (0)