Skip to content

Commit 52e244e

Browse files
NONE add type annotations for errors (#2468)
1 parent ddbcfc9 commit 52e244e

File tree

101 files changed

+196
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+196
-172
lines changed

prestart.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const waitForTunnel = async () => {
3838
envContents = envContents.replace(/WEBHOOK_PROXY_URL=.*/, `WEBHOOK_PROXY_URL=${ngrokDomain}/github/webhooks`);
3939
fs.writeFileSync(envFilePath, envContents);
4040
console.info(`Updated ${envFileName} file to use ngrok domain '${ngrokDomain}'.`);
41-
} catch (e) {
41+
} catch (e: unknown) {
4242
console.info(`'${envFilePath}' not found, skipping...`);
4343
}
4444
} else {
@@ -68,7 +68,7 @@ const callQueues = async () => {
6868
await axios.get(value);
6969
console.info(`Queue ${value} is ready...`);
7070
return Promise.resolve();
71-
} catch (e) {
71+
} catch (e: unknown) {
7272
console.warn(`Queue ${value} not ready...`);
7373
return Promise.reject();
7474
}
@@ -111,7 +111,7 @@ const createEnvFile = async () => {
111111
waitForQueues()
112112
]);
113113
process.exit();
114-
} catch (e) {
114+
} catch (e: unknown) {
115115
process.exit(1);
116116
}
117117
})();

spa/src/pages/ConfigSteps/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const ConfigSteps = () => {
186186
await OAuthManager.authenticateInGitHub(() => {
187187
setLoaderForLogin(false);
188188
});
189-
} catch (e) {
189+
} catch (e: unknown) {
190190
const errorObj = modifyError(e as AxiosError, {}, { onClearGitHubToken: clearGitHubToken, onRelogin: reLogin });
191191
showError(errorObj);
192192
analyticsClient.sendTrackEvent({ actionSubject: "finishOAuthFlow", action: "fail"}, { errorCode: errorObj.errorCode, step: "initiate-oauth"});
@@ -247,7 +247,7 @@ const ConfigSteps = () => {
247247
analyticsClient.sendTrackEvent({ actionSubject: "organisationConnectResponse", action: (connected === true ? "success" : "fail") }, { mode });
248248
navigate("/spa/connected");
249249
}
250-
} catch (e) {
250+
} catch (e: unknown) {
251251
analyticsClient.sendTrackEvent({ actionSubject: "organisationConnectResponse", action: "fail"}, { mode });
252252
reportError(new Error("Fail doCreateConnection", { cause: e }), {
253253
path: "doCreateConnection",
@@ -273,7 +273,7 @@ const ConfigSteps = () => {
273273
navigate("/spa/installationRequested");
274274
}
275275
});
276-
} catch (e) {
276+
} catch (e: unknown) {
277277
const errorObj = modifyError(e as AxiosError, { }, { onClearGitHubToken: clearGitHubToken, onRelogin: reLogin });
278278
showError(errorObj);
279279
analyticsClient.sendTrackEvent({ actionSubject: "installNewOrgInGithubResponse", action: "fail"}, { mode, errorCode: errorObj.errorCode });
@@ -442,7 +442,7 @@ const setAnalyticsEventsForFetchedOrgs = (orgs: Array<GitHubInstallationType>)
442442
requiresSsoLoginCount,
443443
isIPBlockedCount,
444444
});
445-
} catch (e) {
445+
} catch (e: unknown) {
446446
reportError(new Error("Fail setAnalyticsEventsForFetchedOrgs", { cause: e }), {
447447
path: "setAnalyticsEventsForFetchedOrgs"
448448
});

spa/src/pages/StartConnection/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const getAnalyticsSourceFrom = (): string => {
7575
try {
7676
const url = new URL(window.location.href);
7777
return url.searchParams.get("from") || "";
78-
} catch (e) {
78+
} catch (e: unknown) {
7979
reportError(new Error("Fail getAnalyticsSourceFrom", { cause: e }), { path: "getAnalyticsSourceFrom" });
8080
return "";
8181
}

spa/src/services/app-manager/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function fetchOrgs(): Promise<OrganizationsResponse | AxiosError> {
1010
try {
1111
const response = await Api.orgs.getOrganizations();
1212
return response.data;
13-
} catch (e) {
13+
} catch (e: unknown) {
1414
reportError(new Error("Fail fetchOrgs", { cause: e } ), { path: "fetchOrgs" });
1515
return e as AxiosError;
1616
}
@@ -37,7 +37,7 @@ async function connectOrg(orgId: number): Promise<boolean | AxiosError> {
3737

3838
return ret;
3939

40-
} catch (e) {
40+
} catch (e: unknown) {
4141
reportError(new Error("Fail connectOrg", { cause: e }), { path: "connectOrg" });
4242
return e as AxiosError;
4343
}
@@ -85,7 +85,7 @@ async function installNewApp(callbacks: {
8585
try {
8686
lastOpenWin = null;
8787
setTimeout(() => window.removeEventListener("message", handler), 1000); //give time for above message handler to kick off
88-
} catch (e) {
88+
} catch (e: unknown) {
8989
reportError(new Error("Fail remove listener", { cause: e }), { path: "installNewApp", reason: "Fail remove message listener" });
9090
} finally {
9191
clearInterval(hdlWinInstall);

spa/src/services/oauth-manager/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function checkValidity(): Promise<boolean | AxiosError> {
2727

2828
return ret;
2929

30-
} catch (e) {
30+
} catch (e: unknown) {
3131
reportError(new Error("Fail checkValidity", { cause: e }), { path: "checkValidity" });
3232
return e as AxiosError;
3333
}
@@ -44,7 +44,7 @@ async function authenticateInGitHub(onWinClosed: () => void): Promise<void> {
4444
clearInterval(winCloseCheckHandler);
4545
try {
4646
onWinClosed();
47-
} catch (e) {
47+
} catch (e: unknown) {
4848
reportError(new Error("Fail authenticateInGitHub", { cause: e }), {
4949
path: "authenticateInGitHub",
5050
reason: "error in onWinClosed"
@@ -100,7 +100,7 @@ async function finishOAuthFlow(code: string, state: string): Promise<boolean | A
100100
reportError({ message: "fail to acquire accessToken (empty)" }, { path: "finishOAuthFlow", });
101101
return false;
102102
}
103-
} catch (e) {
103+
} catch (e: unknown) {
104104
reportError(new Error("Fail exchangeToken", { cause: e }), { path: "finishOAuthFlow" });
105105
return e as AxiosError;
106106
}

src/config/feature-flags.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const getLaunchDarklyValue = async <T = boolean | string | number>(flag: Boolean
7171
await launchdarklyClient.waitForInitialization();
7272
const user = createLaunchdarklyUser(key);
7373
return launchdarklyClient.variation(flag, user, defaultValue);
74-
} catch (err) {
74+
} catch (err: unknown) {
7575
logger.error({ flag, err }, "Error resolving value for feature flag");
7676
return defaultValue;
7777
}
@@ -104,7 +104,7 @@ export const shouldSendAll = async (type: ShouldSendAllStringTypes, jiraHost: st
104104
const sendAllString = await stringFlag(StringFlags.SEND_ALL, "[]", jiraHost);
105105
const sendAllArray: string[] = JSON.parse(sendAllString);
106106
return Array.isArray(sendAllArray) && sendAllArray.includes(type);
107-
} catch (e) {
107+
} catch (e: unknown) {
108108
logger.error({ err: e, type }, "Cannot define if should send all");
109109
return false;
110110
}
@@ -115,7 +115,7 @@ export const isBlocked = async (jiraHost: string, installationId: number, logger
115115
const blockedInstallationsString = await stringFlag(StringFlags.BLOCKED_INSTALLATIONS, "[]", jiraHost);
116116
const blockedInstallations: number[] = JSON.parse(blockedInstallationsString);
117117
return Array.isArray(blockedInstallations) && blockedInstallations.includes(installationId);
118-
} catch (e) {
118+
} catch (e: unknown) {
119119
logger.error({ err: e, installationId }, "Cannot define if isBlocked");
120120
return false;
121121
}

src/github/client/github-client-cloud.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe("GitHub Client", () => {
154154
let error: any = undefined;
155155
try {
156156
await client.getPullRequests("owner", "repo", {});
157-
} catch (e) {
157+
} catch (e: unknown) {
158158
error = e;
159159
}
160160

@@ -181,7 +181,7 @@ describe("GitHub Client", () => {
181181
let error: any = undefined;
182182
try {
183183
await client.getPullRequests("owner", "repo", {});
184-
} catch (e) {
184+
} catch (e: unknown) {
185185
error = e;
186186
}
187187

@@ -204,7 +204,7 @@ describe("GitHub Client", () => {
204204
let error: any = undefined;
205205
try {
206206
await client.getPullRequests("owner", "repo", {});
207-
} catch (e) {
207+
} catch (e: unknown) {
208208
error = e;
209209
}
210210

@@ -229,7 +229,7 @@ describe("GitHub Client", () => {
229229
let error: any = undefined;
230230
try {
231231
await client.getPullRequests("owner", "repo", {});
232-
} catch (e) {
232+
} catch (e: unknown) {
233233
error = e;
234234
}
235235

@@ -255,7 +255,7 @@ describe("GitHub Client", () => {
255255
let error: any = undefined;
256256
try {
257257
await client.getPullRequests("owner", "repo", {});
258-
} catch (e) {
258+
} catch (e: unknown) {
259259
error = e;
260260
}
261261

@@ -283,7 +283,7 @@ describe("GitHub Client", () => {
283283
let error: any = undefined;
284284
try {
285285
await client.getPullRequests("owner", "repo", {});
286-
} catch (e) {
286+
} catch (e: unknown) {
287287
error = e;
288288
}
289289

src/github/client/github-client-interceptors.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe("github-client-interceptors", () => {
1717
const client = await createAnonymousClient(gheUrl, jiraHost, { trigger: "test" }, getLogger("test"));
1818
try {
1919
await client.getPage(1000);
20-
} catch (err) {
21-
error = err;
20+
} catch (err: unknown) {
21+
error = err as Error;
2222
}
2323
expect(error!).toBeInstanceOf(GithubClientInvalidPermissionsError);
2424
});
@@ -33,8 +33,8 @@ describe("github-client-interceptors", () => {
3333
const client = await createAnonymousClient(gheUrl, jiraHost, { trigger: "test" }, getLogger("test"));
3434
try {
3535
await client.getPage(1000);
36-
} catch (err) {
37-
error = err;
36+
} catch (err: unknown) {
37+
error = err as Error;
3838
}
3939
expect(error!).toBeInstanceOf(GithubClientNotFoundError);
4040
});
@@ -48,8 +48,8 @@ describe("github-client-interceptors", () => {
4848
const client = await createAnonymousClient(gheUrl, jiraHost, { trigger: "test" }, getLogger("test"));
4949
try {
5050
await client.getPage(1000);
51-
} catch (err) {
52-
error = err;
51+
} catch (err: unknown) {
52+
error = err as Error;
5353
}
5454
expect(error!).toBeInstanceOf(GithubClientBlockedIpError);
5555
});
@@ -61,8 +61,8 @@ describe("github-client-interceptors", () => {
6161
const client = await createAnonymousClient(gheUrl, jiraHost, { trigger: "test" }, getLogger("test"));
6262
try {
6363
await client.getPage(1000);
64-
} catch (err) {
65-
error = err;
64+
} catch (err: unknown) {
65+
error = err as Error;
6666
}
6767
expect(error!).toBeInstanceOf(GithubClientSSOLoginError);
6868
});

src/github/client/github-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let certs: Buffer | undefined = undefined;
6060
try {
6161
certs = fs.readFileSync("node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem");
6262
getLogger("github-client").warn("the bundle is loaded");
63-
} catch (err) {
63+
} catch (err: unknown) {
6464
getLogger("github-client").error({ err }, "cannot read certificate bundle");
6565
}
6666

@@ -111,7 +111,7 @@ export class GitHubClient {
111111
ca: certs
112112
});
113113
}
114-
} catch (err) {
114+
} catch (err: unknown) {
115115
this.logger.error({ err }, "HOT-105065: should never happen, but just in case cause we don't have test for this");
116116
}
117117
return config;

src/github/client/github-installation-client.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ export class GitHubInstallationClient extends GitHubClient {
239239
cursor
240240
}, { graphQuery: "GetRepositoriesQuery" });
241241
return response.data.data;
242-
} catch (err) {
243-
err.isRetryable = true;
242+
} catch (err: unknown) {
243+
(err as any).isRetryable = true;
244244
throw err;
245245
}
246246
};
@@ -271,7 +271,7 @@ export class GitHubInstallationClient extends GitHubClient {
271271
...response,
272272
hasNextPage
273273
};
274-
} catch (err) {
274+
} catch (err: unknown) {
275275
try {
276276
if (await booleanFlag(BooleanFlags.LOG_CURLV_OUTPUT, this.jiraHost)) {
277277
this.logger.warn("Found error listing repos, run curl commands to get more details");
@@ -355,7 +355,7 @@ export class GitHubInstallationClient extends GitHubClient {
355355
{ environment, per_page },
356356
{ owner, repo }
357357
);
358-
} catch (e) {
358+
} catch (e: unknown) {
359359
try {
360360
if (await booleanFlag(BooleanFlags.LOG_CURLV_OUTPUT, this.jiraHost)) {
361361
this.logger.warn("Found error listing deployments, run curl commands to get more details");
@@ -523,8 +523,9 @@ export class GitHubInstallationClient extends GitHubClient {
523523
});
524524

525525
return response.data.content;
526-
} catch (err) {
527-
if (err.status == 404) {
526+
} catch (e: unknown) {
527+
const err = e as { status?: number };
528+
if (err?.status == 404) {
528529
this.logger.debug({ err, owner, repo, path }, "could not find file in repo");
529530
return undefined;
530531
}

src/github/client/github-user-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class GitHubUserClient extends GitHubClient {
5555
cursor
5656
}, { graphQuery: "GetRepositoriesQuery" });
5757
return response.data.data;
58-
} catch (err) {
58+
} catch (err: unknown) {
5959
this.logger.error({ err }, "Could not fetch repositories");
6060
throw err;
6161
}
@@ -67,7 +67,7 @@ export class GitHubUserClient extends GitHubClient {
6767
first
6868
}, { graphQuery: "UserOrganizationsQuery" });
6969
return response.data.data;
70-
} catch (err) {
70+
} catch (err: unknown) {
7171
this.logger.error({ err }, "Could not fetch organizations");
7272
throw err;
7373
}

src/github/client/installation-token-cache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class InstallationTokenCache {
3838
this.logger.info({ newMax, oldMax: this.installationTokenCache.max }, "Found new max cache size, now updating cache options.");
3939
this.installationTokenCache.max = newMax;
4040
this.logger.info({ max: this.installationTokenCache.max }, "InstallationTokenCache max udpated");
41-
} catch (e) {
41+
} catch (e: unknown) {
4242
this.logger.error("Error updating InstallationTokenCache max");
4343
}
4444
}

src/github/deployment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const tryCacheSuccessfulDeploymentInfo = async (
127127
}, logger);
128128
statsd.increment(metricDeploymentCache.created, tags, info);
129129
logger.info("Saved deployment information to dynamodb");
130-
} catch (e) {
130+
} catch (e: unknown) {
131131
statsd.increment(metricDeploymentCache.failed, { failType: "persist", ...tags }, info);
132132
logger.error({ err: e }, "Error saving deployment information to dynamodb");
133133
}

src/github/installation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const installationWebhookHandler = async (
7171
gitHubAppId
7272
);
7373

74-
} catch (err) {
74+
} catch (err: unknown) {
7575
logger.warn({ err }, "Failed to submit security workspace to Jira or trigger backfill");
7676
const webhookReceived = context.webhookReceived;
7777
webhookReceived && emitWebhookProcessedMetrics(
@@ -93,7 +93,7 @@ const hasSecurityPermissionsAndEvents = (permissions: InstallationEvent["install
9393
const setSecurityPermissionAccepted = async (subscription: Subscription, logger: Logger) => {
9494
try {
9595
await subscription.update({ isSecurityPermissionsAccepted: true });
96-
} catch (err) {
96+
} catch (err: unknown) {
9797
logger.warn({ err }, "Failed to set security permissions accepted field in Subscriptions");
9898
}
9999
};

src/github/issue-comment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const issueCommentWebhookHandler = async (
4747
context.log.debug("Halting further execution for issueComment since linkifiedBody is empty");
4848
return;
4949
}
50-
} catch (err) {
50+
} catch (err: unknown) {
5151
context.log.warn(
5252
{ err, linkifiedBody, body: comment.body },
5353
"Error while trying to find Jira keys in comment body"
@@ -66,7 +66,7 @@ export const issueCommentWebhookHandler = async (
6666
try {
6767
const githubResponse: GitHubIssue = await gitHubInstallationClient.updateIssueComment(updatedIssueComment);
6868
status = githubResponse.status;
69-
} catch (err) {
69+
} catch (err: unknown) {
7070
context.log.warn({ err }, "Cannot modify issue comment");
7171
}
7272
const { webhookReceived, name, log } = context;

src/github/issue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const issueWebhookHandler = async (context: WebhookContext<IssuesOpenedEv
3535
context.log.info("Halting further execution for issue since linkifiedBody is empty");
3636
return;
3737
}
38-
} catch (err) {
38+
} catch (err: unknown) {
3939
context.log.warn(
4040
{ err, linkifiedBody, body: issue.body },
4141
"Error while trying to find jira keys in issue body"

0 commit comments

Comments
 (0)