diff --git a/src/commands/deployment/onboard.test.ts b/src/commands/deployment/onboard.test.ts index c65e5c2d1..12e8b2bea 100644 --- a/src/commands/deployment/onboard.test.ts +++ b/src/commands/deployment/onboard.test.ts @@ -315,7 +315,7 @@ describe("onboard", () => { expect(true).toBe(false); } catch (err) { expect(err.message).toBe( - "the following argument is required: \n -l / --storage-location" + getErrorMessage("introspect-onboard-cmd-location-missing") ); } }); @@ -334,7 +334,10 @@ describe("onboard", () => { expect(true).toBe(false); } catch (err) { expect(err.message).toBe( - "Storage account testaccount access keys in resource group testResourceGroup is not defined" + getErrorMessage({ + errorKey: "introspect-onboard-cmd-get-storage-access-key-err", + values: ["testaccount", "testResourceGroup"], + }) ); } }); diff --git a/src/commands/deployment/onboard.ts b/src/commands/deployment/onboard.ts index f5ba550fc..c55df13c6 100644 --- a/src/commands/deployment/onboard.ts +++ b/src/commands/deployment/onboard.ts @@ -15,6 +15,8 @@ import { populateInheritValueFromConfig, validateForRequiredValues, } from "../../lib/commandBuilder"; +import { build as buildError, log as logError } from "../../lib/errorBuilder"; +import { errorStatusCode } from "../../lib/errorStatusCode"; import { logger } from "../../logger"; import { AzureAccessOpts, ConfigYaml } from "../../types"; import decorator from "./onboard.decorator.json"; @@ -109,6 +111,7 @@ export const setConfiguration = ( fs.writeFileSync(defaultConfigFile(), jsonData); return true; } catch (err) { + // TOFIX: write some comments on why this error can be ignore logger.error( `Unable to set storage account and table names in configuration file. \n ${err}` ); @@ -135,8 +138,9 @@ export const validateAndCreateStorageAccount = async ( // Storage account does not exist so create it. if (isExist === false) { if (!values.storageLocation) { - throw new Error( - "the following argument is required: \n -l / --storage-location" + throw buildError( + errorStatusCode.VALIDATION_ERR, + "introspect-onboard-cmd-location-missing" ); } const storageAccount = await createStorageAccount( @@ -169,9 +173,10 @@ export const getStorageAccessKey = async ( ); if (accessKey === undefined) { - throw new Error( - `Storage account ${values.storageAccountName} access keys in resource group ${values.storageResourceGroupName} is not defined` - ); + throw buildError(errorStatusCode.ENV_SETTING_ERR, { + errorKey: "introspect-onboard-cmd-get-storage-access-key-err", + values: [values.storageAccountName, values.storageResourceGroupName], + }); } return accessKey; }; @@ -248,7 +253,13 @@ export const execute = async ( ); await exitFn(0); } catch (err) { - logger.error(err); + logError( + buildError( + errorStatusCode.CMD_EXE_ERR, + "introspect-onboard-cmd-failed", + err + ) + ); await exitFn(1); } }; diff --git a/src/lib/i18n.json b/src/lib/i18n.json index 0f13b74c9..78c760c3e 100644 --- a/src/lib/i18n.json +++ b/src/lib/i18n.json @@ -124,6 +124,10 @@ "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.", "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.", + "introspect-onboard-cmd-failed": "Deployment onboard command was not successfully executed.", + "introspect-onboard-cmd-location-missing": "Value for --storage-location was missing. Provide it.", + "introspect-onboard-cmd-get-storage-access-key-err": "Could not get storage access key for account, {0} in resource group {1}.", + "introspect-validate-cmd-failed": "Deployment validate command was not successfully executed.", "introspect-validate-cmd-valid-err": "Validation failed. Missing configuration: {0}", "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",