Skip to content

Commit 086487a

Browse files
author
Tom J
committed
errors unknown type | #1666
1 parent a63fb8f commit 086487a

File tree

14 files changed

+44
-41
lines changed

14 files changed

+44
-41
lines changed

extension/chrome/dev/unit_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Env } from '../../js/common/browser.js';
1111
const f = String(uncheckedUrlParams.f);
1212
const args = JSON.parse(String(uncheckedUrlParams.args)) as any[];
1313

14-
const renderRes = (error: any, result?: any) => {
14+
const renderRes = (error: unknown, result?: any) => {
1515
error = (typeof error === 'undefined') ? undefined : String(error);
1616
$('#result').text(JSON.stringify({ error, result }));
1717
$('#result').attr('data-test-state', 'ready');

extension/chrome/elements/attachment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Catch.try(async () => {
6060
}
6161
};
6262

63-
const renderErr = (e: any) => {
63+
const renderErr = (e: unknown) => {
6464
if (Api.err.isAuthPopupNeeded(e)) {
6565
BrowserMsg.send.notificationShowAuthPopupNeeded(parentTabId, { acctEmail });
6666
Xss.sanitizeRender('body.attachment', `Error downloading file - google auth needed. ${Ui.retryLink()}`);

extension/chrome/elements/subscribe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Catch.try(async () => {
2929
let origBtnContent: string;
3030
let origBtnSel: JQuery<HTMLElement>;
3131

32-
const handleErrRes = (e: any) => {
32+
const handleErrRes = (e: unknown) => {
3333
const renderErr = (msg: string, e?: any) => {
3434
msg = Xss.escape(msg);
3535
const debug = e ? `<pre>${Xss.escape(JSON.stringify(e, undefined, 2))}</pre>` : '';

extension/js/background_page/bgutils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class BgUtils {
4444
});
4545
})
4646

47-
public static handleStoreErr = async (e: any, reason?: 'storage_undefined' | 'db_corrupted' | 'db_denied' | 'db_failed') => {
47+
public static handleStoreErr = async (e: unknown, reason?: 'storage_undefined' | 'db_corrupted' | 'db_denied' | 'db_failed') => {
4848
if (!reason) {
4949
if (e instanceof StoreCorruptedError) {
5050
reason = 'db_corrupted';

extension/js/background_page/migrations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const accountUpdateStatusKeyserver = async (acctEmail: string) => { // checks wh
5656
}
5757
};
5858

59-
const reportSignificantErrs = (e: any) => {
59+
const reportSignificantErrs = (e: unknown) => {
6060
if (Api.err.isSignificant(e)) {
6161
Catch.reportErr(e);
6262
}

extension/js/common/api/api.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export namespace R { // responses
201201
export class Api {
202202

203203
public static err = {
204-
eli5: (e: any) => {
204+
eli5: (e: unknown) => {
205205
if (Api.err.isMailOrAcctDisabled(e)) {
206206
return 'Email account is disabled';
207207
} else if (Api.err.isAuthPopupNeeded(e)) {
@@ -228,7 +228,7 @@ export class Api {
228228
return 'FlowCrypt encountered an error with unknown cause.';
229229
}
230230
},
231-
detailsAsHtmlWithNewlines: (e: any) => {
231+
detailsAsHtmlWithNewlines: (e: unknown) => {
232232
let details = 'Below are technical details about the error. This may be useful for debugging.\n\n';
233233
details += `<b>Error string</b>: ${Xss.escape(String(e))}\n\n`;
234234
details += `<b>Error stack</b>: ${e instanceof Error ? Xss.escape((e.stack || '(empty)')) : '(no error stack)'}\n\n`;
@@ -237,7 +237,7 @@ export class Api {
237237
}
238238
return details;
239239
},
240-
isNetErr: (e: any) => {
240+
isNetErr: (e: unknown) => {
241241
if (e instanceof TypeError && (e.message === 'Failed to fetch' || e.message === 'NetworkError when attempting to fetch resource.')) {
242242
return true; // openpgp.js uses fetch()... which produces these errors
243243
}
@@ -249,7 +249,7 @@ export class Api {
249249
}
250250
return false;
251251
},
252-
isAuthErr: (e: any) => {
252+
isAuthErr: (e: unknown) => {
253253
if (e instanceof AuthError) {
254254
return true;
255255
}
@@ -263,7 +263,7 @@ export class Api {
263263
}
264264
return false;
265265
},
266-
isStandardErr: (e: any, internalType: string) => {
266+
isStandardErr: (e: unknown, internalType: string) => {
267267
if (e instanceof ApiErrorResponse && typeof e.res === 'object' && typeof e.res.error === 'object' && e.res.error.internal === 'auth') {
268268
return true;
269269
}
@@ -275,7 +275,7 @@ export class Api {
275275
}
276276
return false;
277277
},
278-
isAuthPopupNeeded: (e: any) => {
278+
isAuthPopupNeeded: (e: unknown) => {
279279
if (e instanceof AjaxError && e.status === 400 && typeof e.responseText === 'string') {
280280
try {
281281
const json = JSON.parse(e.responseText);
@@ -289,18 +289,18 @@ export class Api {
289289
}
290290
return false;
291291
},
292-
isMailOrAcctDisabled: (e: any): boolean => {
292+
isMailOrAcctDisabled: (e: unknown): boolean => {
293293
if (Api.err.isBadReq(e) && typeof e.responseText === 'string') {
294294
return e.responseText.indexOf('Mail service not enabled') !== -1 || e.responseText.indexOf('Account has been deleted') !== -1;
295295
}
296296
return false;
297297
},
298-
isInsufficientPermission: (e: any): e is AjaxError => e instanceof AjaxError && e.status === 403 && e.responseText.indexOf('insufficientPermissions') !== -1,
299-
isNotFound: (e: any): e is AjaxError => e instanceof AjaxError && e.status === 404,
300-
isBadReq: (e: any): e is AjaxError => e instanceof AjaxError && e.status === 400,
301-
isReqTooLarge: (e: any): e is AjaxError => e instanceof AjaxError && e.status === 413,
302-
isServerErr: (e: any): e is AjaxError => e instanceof AjaxError && e.status >= 500,
303-
isBlockedByProxy: (e: any): e is AjaxError => {
298+
isInsufficientPermission: (e: unknown): e is AjaxError => e instanceof AjaxError && e.status === 403 && e.responseText.indexOf('insufficientPermissions') !== -1,
299+
isNotFound: (e: unknown): e is AjaxError => e instanceof AjaxError && e.status === 404,
300+
isBadReq: (e: unknown): e is AjaxError => e instanceof AjaxError && e.status === 400,
301+
isReqTooLarge: (e: unknown): e is AjaxError => e instanceof AjaxError && e.status === 413,
302+
isServerErr: (e: unknown): e is AjaxError => e instanceof AjaxError && e.status >= 500,
303+
isBlockedByProxy: (e: unknown): e is AjaxError => {
304304
if (!(e instanceof AjaxError)) {
305305
return false;
306306
}
@@ -314,11 +314,11 @@ export class Api {
314314
}
315315
return false;
316316
},
317-
isSignificant: (e: any) => {
317+
isSignificant: (e: unknown) => {
318318
return !Api.err.isNetErr(e) && !Api.err.isServerErr(e) && !Api.err.isNotFound(e) && !Api.err.isMailOrAcctDisabled(e) && !Api.err.isAuthErr(e)
319319
&& !Api.err.isBlockedByProxy(e);
320320
},
321-
isInPrivateMode: (e: any) => {
321+
isInPrivateMode: (e: unknown) => {
322322
return e instanceof Error && e.message.startsWith('BrowserMsg() (no status text): -1 when GET-ing blob:moz-extension://');
323323
}
324324
};
@@ -667,10 +667,10 @@ export class Api {
667667
}
668668

669669
private static internal = {
670-
isStandardError: (e: any): e is StandardError => {
670+
isStandardError: (e: unknown): e is StandardError => {
671671
return e && typeof e === 'object' && (e as StandardError).hasOwnProperty('internal') && Boolean((e as StandardError).message);
672672
},
673-
isRawAjaxError: (e: any): e is RawAjaxError => {
673+
isRawAjaxError: (e: unknown): e is RawAjaxError => {
674674
return e && typeof e === 'object' && typeof (e as RawAjaxError).readyState === 'number';
675675
},
676676
apiCall: async (url: string, path: string, fields: Dict<any>, fmt: ReqFmt, progress?: ProgressCbs, headers?: Dict<string>, resFmt: ResFmt = 'json', method: ReqMethod = 'POST') => {

extension/js/common/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type AttLimits = { count?: number, size?: number, sizeMb?: number, oversi
3535
export type WebMailName = 'gmail' | 'outlook' | 'settings';
3636
export type WebmailVariantString = undefined | 'html' | 'standard' | 'new';
3737
export type PassphraseDialogType = 'embedded' | 'message' | 'attachment' | 'draft' | 'sign';
38-
export type BrowserEventErrHandler = { auth?: () => Promise<void>, authPopup?: () => Promise<void>, network?: () => Promise<void>, other?: (e: any) => Promise<void> };
38+
export type BrowserEventErrHandler = { auth?: () => Promise<void>, authPopup?: () => Promise<void>, network?: () => Promise<void>, other?: (e: unknown) => Promise<void> };
3939
export type SelCache = { cached: (name: string) => JQuery<HTMLElement>; now: (name: string) => JQuery<HTMLElement>; sel: (name: string) => string; };
4040
export type UrlParam = string | number | null | undefined | boolean | string[];
4141
export type UrlParams = Dict<UrlParam>;
@@ -455,7 +455,7 @@ export class Ui {
455455
}
456456
};
457457
},
458-
_dispatchErr: (e: any, errHandlers?: BrowserEventErrHandler) => {
458+
_dispatchErr: (e: unknown, errHandlers?: BrowserEventErrHandler) => {
459459
if (Api.err.isNetErr(e) && errHandlers && errHandlers.network) {
460460
errHandlers.network().catch(Catch.reportErr);
461461
} else if (Api.err.isAuthErr(e) && errHandlers && errHandlers.auth) {

extension/js/common/composer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class Composer {
227227
BrowserMsg.send.subscribeDialog(this.urlParams.parentTabId, { isAuthErr: true });
228228
}
229229
},
230-
other: async (e: any) => {
230+
other: async (e: unknown) => {
231231
if (e instanceof Error) {
232232
e.stack = (e.stack || '') + `\n\n[compose action: ${couldNotDoWhat}]`;
233233
} else if (typeof e === 'object' && e && typeof (e as any).stack === 'undefined') {
@@ -606,7 +606,7 @@ export class Composer {
606606
}
607607
}
608608

609-
private handleSendErr = async (e: any) => {
609+
private handleSendErr = async (e: unknown) => {
610610
if (Api.err.isNetErr(e)) {
611611
await Ui.modal.error('Could not send message due to network error. Please check your internet connection and try again.');
612612
} else if (Api.err.isAuthPopupNeeded(e)) {

extension/js/common/core/pgp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ export class Pgp {
557557
}
558558
return keys;
559559
},
560-
cryptoMsgDecryptCategorizeErr: (decryptErr: any, msgPwd?: string): DecryptError$error => {
560+
cryptoMsgDecryptCategorizeErr: (decryptErr: unknown, msgPwd?: string): DecryptError$error => {
561561
const e = String(decryptErr).replace('Error: ', '').replace('Error decrypting message: ', '');
562562
const keyMismatchErrStrings = ['Cannot read property \'isDecrypted\' of null', 'privateKeyPacket is null',
563563
'TypeprivateKeyPacket is null', 'Session key decryption failed.', 'Invalid session key for decryption.'];

extension/js/common/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type Handler = Bm.AsyncRespondingHandler | Bm.AsyncResponselessHandler;
102102
export type Handlers = Dict<Handler>;
103103
export type AddrParserResult = { name?: string, address?: string };
104104
export interface BrowserWidnow extends Window {
105-
onunhandledrejection: (e: any) => void;
105+
onunhandledrejection: (e: unknown) => void;
106106
'emailjs-mime-codec': AnyThirdPartyLibrary;
107107
'emailjs-mime-parser': AnyThirdPartyLibrary;
108108
'emailjs-mime-builder': AnyThirdPartyLibrary;
@@ -331,7 +331,7 @@ export class BrowserMsg {
331331
return requestOrResponse;
332332
}
333333

334-
private static errToJson = (e: any): Bm.ErrAsJson => {
334+
private static errToJson = (e: unknown): Bm.ErrAsJson => {
335335
if (e instanceof AjaxError) {
336336
const { message, stack, status, url, responseText, statusText } = e;
337337
return { stack, message, errorConstructor: 'AjaxError', ajaxErrorDetails: { status, url, responseText, statusText } };

extension/js/common/platform/catch.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export class Catch {
3131
'ResizeObserver loop limit exceeded',
3232
];
3333

34-
public static rewrapErr = (e: any, message: string) => {
34+
public static rewrapErr = (e: unknown, message: string) => {
3535
const newErr = new Error(`${message}::${e instanceof Error ? `${e.name}: ${e.message}` : String(e)}`);
3636
newErr.stack += `\n\n${Catch.stringify(e)}`;
3737
return newErr;
3838
}
3939

40-
public static stringify = (e: any) => {
40+
public static stringify = (e: unknown) => {
4141
if (e instanceof Error) {
4242
return `[typeof:Error:${e.name}] ${e.message}\n\n${e.stack}`;
4343
}
@@ -51,11 +51,11 @@ export class Catch {
5151
}
5252
}
5353

54-
public static hasStack = (e: any): e is ObjWithStack => {
54+
public static hasStack = (e: unknown): e is ObjWithStack => {
5555
return e && typeof e === 'object' && typeof (e as ObjWithStack).stack === 'string' && Boolean((e as ObjWithStack).stack);
5656
}
5757

58-
public static onErrorInternalHandler = (errMsg: string | undefined, url: string, line: number, col: number, originalErr: any, isManuallyCalled: boolean) => {
58+
public static onErrorInternalHandler = (errMsg: string | undefined, url: string, line: number, col: number, originalErr: unknown, isManuallyCalled: boolean) => {
5959
if (errMsg && Catch.IGNORE_ERR_MSG.indexOf(errMsg) !== -1) {
6060
return;
6161
}
@@ -135,7 +135,10 @@ export class Catch {
135135
return true;
136136
}
137137

138-
private static getErrorLineAndCol = (e: any) => {
138+
private static getErrorLineAndCol = (e: unknown) => {
139+
if (!Catch.hasStack(e)) {
140+
return { line: 0, col: 0 };
141+
}
139142
try {
140143
const callerLine = e.stack!.split('\n')[1]; // tslint:disable-line:no-unsafe-any
141144
const matched = callerLine.match(/\.js:([0-9]+):([0-9]+)\)?/); // tslint:disable-line:no-unsafe-any
@@ -145,7 +148,7 @@ export class Catch {
145148
}
146149
}
147150

148-
public static reportErr = (e: any) => {
151+
public static reportErr = (e: unknown) => {
149152
const { line, col } = Catch.getErrorLineAndCol(e);
150153
Catch.onErrorInternalHandler(e instanceof Error ? e.message : String(e), window.location.href, line, col, e, true);
151154
}
@@ -257,7 +260,7 @@ export class Catch {
257260
return false;
258261
}
259262

260-
public static onUnhandledRejectionInternalHandler = (e: any) => {
263+
public static onUnhandledRejectionInternalHandler = (e: unknown) => {
261264
if (Catch.isPromiseRejectionEvent(e)) {
262265
Catch.reportErr(e.reason);
263266
} else {

extension/js/common/platform/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class Store {
320320
return Store.buildSingleAccountStoreFromRawResults(Store.globalStorageScope, storageObj) as GlobalStore;
321321
}
322322

323-
static saveError = (err: any, errMsg?: string) => {
323+
static saveError = (err: unknown, errMsg?: string) => {
324324
Store.getGlobal(['errors']).then(s => {
325325
if (typeof s.errors === 'undefined') {
326326
s.errors = [];
@@ -426,7 +426,7 @@ export class Store {
426426
return str.normalize('NFKD').replace(/[\u0300-\u036F]/g, '').toLowerCase();
427427
}
428428

429-
public static errCategorize = (err: any): Error => {
429+
public static errCategorize = (err: unknown): Error => {
430430
let message: string;
431431
if (err instanceof Error) {
432432
message = err.message;

extension/js/common/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class Settings {
272272
});
273273
}
274274

275-
static promptToRetry = async (type: 'REQUIRED', lastErr: any, userMsg: string, retryCb: () => Promise<void>): Promise<void> => {
275+
static promptToRetry = async (type: 'REQUIRED', lastErr: unknown, userMsg: string, retryCb: () => Promise<void>): Promise<void> => {
276276
while (await Ui.renderOverlayPromptAwaitUserChoice({ retry: {} }, `${userMsg} ${Api.err.eli5(lastErr)}`, Api.err.detailsAsHtmlWithNewlines(lastErr)) === 'retry') {
277277
try {
278278
return await retryCb();

test/source/browser/browser_pool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class BrowserPool {
118118
cb().then(resolve, reject);
119119
})
120120

121-
private processTestError = (err: any, t: AvaContext, attemptHtmls: string[]) => {
121+
private processTestError = (err: unknown, t: AvaContext, attemptHtmls: string[]) => {
122122
t.retry = undefined;
123123
if (t.attemptNumber! < t.totalAttempts!) {
124124
t.log(`${t.attemptText} Retrying: ${String(err)}`);
@@ -129,7 +129,7 @@ export class BrowserPool {
129129
}
130130
}
131131

132-
private testFailSingleAttemptDebugHtml = async (t: AvaContext, browser: BrowserHandle, err: any): Promise<string> => `
132+
private testFailSingleAttemptDebugHtml = async (t: AvaContext, browser: BrowserHandle, err: unknown): Promise<string> => `
133133
<div class="attempt">
134134
<div style="display:none;">
135135
<pre title="err.stack">${Util.htmlEscape((err instanceof Error ? err.stack : String(err)) || String(err))}</pre>

0 commit comments

Comments
 (0)