refactor(dev-infra): add JSDoc throws description to assertion functions (#42454)

Adds the JSDoc `@throws` annotation to functions that would throw
within in the ng-dev tool. We want to add `@throws` so clearly
communicate if the invocation of a function results in errors or not.

This helps if IDEs show the `@throws` annotation on invocation, or
if TS ever lands a feature like Java `throws`, with more fine-grained
and typed error handling.

PR Close #42454
This commit is contained in:
Paul Gschwendtner 2021-06-02 18:47:01 +02:00 committed by Andrew Kushnir
parent d3531a7d41
commit 107f15df03
1 changed files with 9 additions and 5 deletions

View File

@ -170,8 +170,7 @@ type RawPullRequest = typeof PR_SCHEMA;
async function fetchPullRequestFromGithub( async function fetchPullRequestFromGithub(
git: GitClient<true>, prNumber: number): Promise<RawPullRequest|null> { git: GitClient<true>, prNumber: number): Promise<RawPullRequest|null> {
try { try {
const x = await getPr(PR_SCHEMA, prNumber, git); return await getPr(PR_SCHEMA, prNumber, git);
return x;
} catch (e) { } catch (e) {
// If the pull request could not be found, we want to return `null` so // If the pull request could not be found, we want to return `null` so
// that the error can be handled gracefully. // that the error can be handled gracefully.
@ -188,8 +187,9 @@ export function isPullRequest(v: PullRequestFailure|PullRequest): v is PullReque
} }
/** /**
* Assert the commits provided are allowed to merge to the provided target label, throwing a * Assert the commits provided are allowed to merge to the provided target label,
* PullRequestFailure otherwise. * throwing an error otherwise.
* @throws {PullRequestFailure}
*/ */
function assertChangesAllowForTargetLabel( function assertChangesAllowForTargetLabel(
commits: Commit[], label: TargetLabel, config: MergeConfig) { commits: Commit[], label: TargetLabel, config: MergeConfig) {
@ -230,6 +230,7 @@ function assertChangesAllowForTargetLabel(
/** /**
* Assert the pull request has the proper label for breaking changes if there are breaking change * Assert the pull request has the proper label for breaking changes if there are breaking change
* commits, and only has the label if there are breaking change commits. * commits, and only has the label if there are breaking change commits.
* @throws {PullRequestFailure}
*/ */
function assertCorrectBreakingChangeLabeling( function assertCorrectBreakingChangeLabeling(
commits: Commit[], labels: string[], config: MergeConfig) { commits: Commit[], labels: string[], config: MergeConfig) {
@ -248,7 +249,10 @@ function assertCorrectBreakingChangeLabeling(
} }
/** Assert the pull request is pending, not closed, merged or in draft. */ /**
* Assert the pull request is pending, not closed, merged or in draft.
* @throws {PullRequestFailure} if the pull request is not pending.
*/
function assertPendingState(pr: RawPullRequest) { function assertPendingState(pr: RawPullRequest) {
if (pr.isDraft) { if (pr.isDraft) {
throw PullRequestFailure.isDraft(); throw PullRequestFailure.isDraft();