This repository was archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add error codes to service commands #533
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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")], | ||
}); | ||
} | ||
logger.info( | ||
`Creating pull request against branches: ${defaultRings.join(", ")}` | ||
|
@@ -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" | ||
); | ||
} | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
) | ||
); | ||
await exitFn(1); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe
join
should bepath.join
There was a problem hiding this comment.
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";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it thanks