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

Add error codes to service commands #533

Merged
merged 3 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/commands/service/create-revision.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { write } from "../../config";
import * as config from "../../config";
import * as bedrockYaml from "../../lib/bedrockYaml";
import * as azure from "../../lib/git/azure";
Expand Down
34 changes: 20 additions & 14 deletions src/commands/service/create-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { hasValue } from "../../lib/validator";
import { logger } from "../../logger";
import { BedrockFile } from "../../types";
import decorator from "./create-revision.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

export interface CommandOptions {
sourceBranch: string | undefined;
Expand Down Expand Up @@ -69,12 +71,10 @@ export const getDefaultRings = (
.filter((ring) => !!ring.isDefault)
.map((ring) => ring.branch);
if (defaultRings.length === 0) {
throw Error(
`Default branches/rings must either be specified in ${join(
__dirname,
"bedrock.yaml"
)} or provided via --target-branch`
);
throw buildError(errorStatusCode.VALIDATION_ERR, {
errorKey: "service-create-revision-cmd-err-default-branch-missing",
values: [join(__dirname, "bedrock.yaml")],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe join should be path.join

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dennisseah it's imported above from the module:

line 2:
import { join } from "path";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it thanks

});
}
logger.info(
`Creating pull request against branches: ${defaultRings.join(", ")}`
Expand All @@ -97,8 +97,9 @@ export const getSourceBranch = async (
);
sourceBranch = await getCurrentBranch();
if (sourceBranch.length === 0) {
throw Error(
`Zero length branch string parsed from git client; cannot automate PR`
throw buildError(
errorStatusCode.VALIDATION_ERR,
"service-create-revision-cmd-err-source-branch-missing"
);
}
}
Expand Down Expand Up @@ -167,17 +168,22 @@ export const execute = async (

// Make sure the user isn't trying to make a PR for a branch against itself
if (defaultRings.includes(values.sourceBranch)) {
throw Error(
`A pull request for a branch cannot be made against itself. Ensure your target branch(es) '${JSON.stringify(
defaultRings
)}' do not include your source branch '${values.sourceBranch}'`
);
throw buildError(errorStatusCode.VALIDATION_ERR, {
errorKey: "service-create-revision-cmd-err-pr-source-branch",
values: [JSON.stringify(defaultRings), values.sourceBranch],
});
}

await makePullRequest(defaultRings, values);
await exitFn(0);
} catch (err) {
logger.error(err);
logError(
buildError(
errorStatusCode.CMD_EXE_ERR,
"service-create-revision-cmd-failed",
err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

)
);
await exitFn(1);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/service/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
CommandValues,
validateGitUrl,
} from "./create";
import { BedrockServiceConfig, HelmConfig } from "../../types";
import { BedrockServiceConfig } from "../../types";

jest.mock("../../lib/gitutils");

Expand Down
5 changes: 5 additions & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
"project-create-variable-group-cmd-err-values-missing": "Required values were missing. Provide values for registry-name, hld-repo-url, service-principal-id, service-principal-password, tenant.",
"project-init-cmd-failed": "Project init was not successfully executed.",

"service-create-revision-cmd-failed": "Service create revision was not successfully executed.",
"service-create-revision-cmd-err-pr-source-branch": "A pull request for a branch cannot be made against itself. Ensure your target branch(es) '{0}' do not include your source branch '{1}'",
"service-create-revision-cmd-err-default-branch-missing": "Default branch/ring was not found. Specify the default branch/ring in {0} or provide it via --target-branch",
"service-create-revision-cmd-err-source-branch-missing": "A source branch was not provided.",

"validation-err-missing-vals": "These mandatory options were missing:\n {0}. Provide them.",
"validation-err-org-name-missing": "Organization name was missing. Provide it.",
"validation-err-org-name": "Organization name must start with a letter or number, followed by letters, numbers or hyphens, and must end with a letter or number.",
Expand Down
1 change: 0 additions & 1 deletion src/lib/ioUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from "fs";
import os from "os";
import path from "path";
import uuid from "uuid/v4";
import { logger } from "../logger";

/**
* Creates a random directory in tmp directory.
Expand Down