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

Commit e433182

Browse files
authored
[FEATURE] added error code to hld install-manifest-pipeline command (#526)
* [FEATURE] added error code to hld install-manifest-pipeline command * correct error identifier
1 parent 8b3b77c commit e433182

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/commands/hld/pipeline.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,15 @@ describe("test populateValues function", () => {
182182
pipelineName: "",
183183
yamlFileBranch: "",
184184
})
185-
).toThrow(`GitHub repos are not supported`);
185+
).toThrow(
186+
getErrorMessage({
187+
errorKey: "hld-install-manifest-pipeline-cmd-validate-repo-err",
188+
values: [
189+
"https://github.com/fabrikam/hld",
190+
"https://github.com/fabrikam/materialized",
191+
],
192+
})
193+
);
186194
});
187195
it("negative tests: missing and invalid org name", () => {
188196
orgNameTest(false);

src/commands/hld/pipeline.ts

+19-30
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
BUILD_SCRIPT_URL,
1717
RENDER_HLD_PIPELINE_FILENAME,
1818
} from "../../lib/constants";
19+
import { build as buildError, log as logError } from "../../lib/errorBuilder";
20+
import { errorStatusCode } from "../../lib/errorStatusCode";
1921
import { AzureDevOpsOpts } from "../../lib/git";
2022
import { getRepositoryName, isGitHubUrl } from "../../lib/gitutils";
2123
import {
@@ -52,7 +54,10 @@ const validateRepos = (hldRepoUrl: string, manifestRepoUrl: string): void => {
5254
const hldGitUrlType = isGitHubUrl(hldRepoUrl);
5355
const manifestGitUrlType = isGitHubUrl(manifestRepoUrl);
5456
if (hldGitUrlType || manifestGitUrlType) {
55-
throw Error(`GitHub repos are not supported`);
57+
throw buildError(errorStatusCode.GIT_OPS_ERR, {
58+
errorKey: "hld-install-manifest-pipeline-cmd-validate-repo-err",
59+
values: [hldRepoUrl, manifestRepoUrl],
60+
});
5661
}
5762
};
5863

@@ -122,8 +127,6 @@ export const requiredPipelineVariables = (
122127
export const installHldToManifestPipeline = async (
123128
values: CommandOptions
124129
): Promise<void> => {
125-
let builtDefinition;
126-
127130
const devopsClient = await getBuildApiClient(
128131
values.orgName,
129132
values.personalAccessToken
@@ -149,34 +152,22 @@ export const installHldToManifestPipeline = async (
149152
`Attempting to create new pipeline: ${values.pipelineName} defined in repository:${values.hldUrl}, branch: ${values.yamlFileBranch}, filePath: ${RENDER_HLD_PIPELINE_FILENAME}`
150153
);
151154

152-
try {
153-
builtDefinition = await createPipelineForDefinition(
154-
devopsClient as IBuildApi,
155-
values.devopsProject,
156-
definition
157-
);
158-
} catch (err) {
159-
logger.error(
160-
`Error occurred during pipeline creation for ${values.pipelineName}`
161-
);
162-
throw err; // caller will catch and exit
163-
}
155+
// createPipelineForDefinition is already throwing error code.
156+
const builtDefinition = await createPipelineForDefinition(
157+
devopsClient as IBuildApi,
158+
values.devopsProject,
159+
definition
160+
);
164161

165162
logger.info(`Created pipeline for ${values.pipelineName}`);
166163
logger.info(`Pipeline ID: ${(builtDefinition as BuildDefinition).id}`);
167164

168-
try {
169-
await queueBuild(
170-
devopsClient as IBuildApi,
171-
values.devopsProject,
172-
builtDefinition.id as number
173-
);
174-
} catch (err) {
175-
logger.error(
176-
`Error occurred when queueing build for ${values.pipelineName}`
177-
);
178-
throw err; // caller will catch and exit
179-
}
165+
// queueBuild is already throwing error code.
166+
await queueBuild(
167+
devopsClient as IBuildApi,
168+
values.devopsProject,
169+
builtDefinition.id as number
170+
);
180171
};
181172

182173
export const execute = async (
@@ -202,9 +193,7 @@ export const execute = async (
202193
await installHldToManifestPipeline(opts);
203194
await exitFn(0);
204195
} catch (err) {
205-
logger.error(
206-
`Error occurred installing pipeline for HLD to Manifest pipeline`
207-
);
196+
logError(buildError(errorStatusCode.CMD_EXE_ERR, "", err));
208197
logger.error(err);
209198
await exitFn(1);
210199
}

src/lib/i18n.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"bedrock-config-invalid": "Invalid helm configuration found in {0}.",
3131
"config-file-not-defined": "Pipeline yaml file name is undefined.",
3232

33-
"hld-init-cmd-failed": "Hld init command was not successfully executed.",
33+
"hld-init-cmd-failed": "hld init command was not successfully executed.",
3434
"hld-init-cmd-project-path-missing": "Value for project path was not provided. Provide it.",
3535

3636
"hld-reconcile-err-repo-create": "Error creating repository component '{0}' in path '{1}'.",
@@ -45,6 +45,9 @@
4545
"hld-reconcile-err-cmd-exe": "An error occurred while reconciling HLD.",
4646
"hld-reconcile-err-purge-repo-comps": "Could not purge hld repository component {0} in path {1}.",
4747

48+
"hld-install-manifest-pipeline-cmd-failed": "hld install-manifest-pipeline command was not successfully executed.",
49+
"hld-install-manifest-pipeline-cmd-validate-repo-err": "Could not validate repositories. {0} and/or {1} may not be supported.",
50+
4851
"infra-scaffold-cmd-failed": "Infra scaffold command was not successfully executed.",
4952
"infra-scaffold-cmd-src-missing": "Value for source is required because it cannot be constructed with properties in spk-config.yaml. Provide value for source.",
5053
"infra-scaffold-cmd-values-missing": "Values for name, version and/or 'template were missing. Provide value for values for them.",

0 commit comments

Comments
 (0)