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 } };

0 commit comments

Comments
 (0)