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

Commit 5d1904c

Browse files
[FEATURE] Specific error code for deployment onboard command (#516)
* [FEATURE] Specific error code for deployment onboard command * Update onboard.test.ts Co-authored-by: Andre Briggs <[email protected]>
1 parent fd3f420 commit 5d1904c

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/commands/deployment/onboard.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ describe("onboard", () => {
315315
expect(true).toBe(false);
316316
} catch (err) {
317317
expect(err.message).toBe(
318-
"the following argument is required: \n -l / --storage-location"
318+
getErrorMessage("introspect-onboard-cmd-location-missing")
319319
);
320320
}
321321
});
@@ -334,7 +334,10 @@ describe("onboard", () => {
334334
expect(true).toBe(false);
335335
} catch (err) {
336336
expect(err.message).toBe(
337-
"Storage account testaccount access keys in resource group testResourceGroup is not defined"
337+
getErrorMessage({
338+
errorKey: "introspect-onboard-cmd-get-storage-access-key-err",
339+
values: ["testaccount", "testResourceGroup"],
340+
})
338341
);
339342
}
340343
});

src/commands/deployment/onboard.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
populateInheritValueFromConfig,
1616
validateForRequiredValues,
1717
} from "../../lib/commandBuilder";
18+
import { build as buildError, log as logError } from "../../lib/errorBuilder";
19+
import { errorStatusCode } from "../../lib/errorStatusCode";
1820
import { logger } from "../../logger";
1921
import { AzureAccessOpts, ConfigYaml } from "../../types";
2022
import decorator from "./onboard.decorator.json";
@@ -109,6 +111,7 @@ export const setConfiguration = (
109111
fs.writeFileSync(defaultConfigFile(), jsonData);
110112
return true;
111113
} catch (err) {
114+
// TOFIX: write some comments on why this error can be ignore
112115
logger.error(
113116
`Unable to set storage account and table names in configuration file. \n ${err}`
114117
);
@@ -135,8 +138,9 @@ export const validateAndCreateStorageAccount = async (
135138
// Storage account does not exist so create it.
136139
if (isExist === false) {
137140
if (!values.storageLocation) {
138-
throw new Error(
139-
"the following argument is required: \n -l / --storage-location"
141+
throw buildError(
142+
errorStatusCode.VALIDATION_ERR,
143+
"introspect-onboard-cmd-location-missing"
140144
);
141145
}
142146
const storageAccount = await createStorageAccount(
@@ -169,9 +173,10 @@ export const getStorageAccessKey = async (
169173
);
170174

171175
if (accessKey === undefined) {
172-
throw new Error(
173-
`Storage account ${values.storageAccountName} access keys in resource group ${values.storageResourceGroupName} is not defined`
174-
);
176+
throw buildError(errorStatusCode.ENV_SETTING_ERR, {
177+
errorKey: "introspect-onboard-cmd-get-storage-access-key-err",
178+
values: [values.storageAccountName, values.storageResourceGroupName],
179+
});
175180
}
176181
return accessKey;
177182
};
@@ -248,7 +253,13 @@ export const execute = async (
248253
);
249254
await exitFn(0);
250255
} catch (err) {
251-
logger.error(err);
256+
logError(
257+
buildError(
258+
errorStatusCode.CMD_EXE_ERR,
259+
"introspect-onboard-cmd-failed",
260+
err
261+
)
262+
);
252263
await exitFn(1);
253264
}
254265
};

src/lib/i18n.json

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@
124124
"introspect-create-cmd-p1-missing-values": "Values for image-tag, commit-id and service options were missing. They are required for updating the details of source pipeline. Provide them.",
125125
"introspect-create-cmd-p2-missing-values": "Values for p2, hld-commit-id, image-tag and env options were missing. They are required For updating the details of image tag release pipeline. Provide them.",
126126

127+
"introspect-onboard-cmd-failed": "Deployment onboard command was not successfully executed.",
128+
"introspect-onboard-cmd-location-missing": "Value for --storage-location was missing. Provide it.",
129+
"introspect-onboard-cmd-get-storage-access-key-err": "Could not get storage access key for account, {0} in resource group {1}.",
130+
127131
"introspect-validate-cmd-failed": "Deployment validate command was not successfully executed.",
128132
"introspect-validate-cmd-valid-err": "Validation failed. Missing configuration: {0}",
129133
"introspect-validate-cmd-missing-vals": "Configuration for introspection storage account and DevOps pipeline to execute this command were missing. Initialize the spk tool with the right configuration",

0 commit comments

Comments
 (0)