diff --git a/.eslintrc b/.eslintrc index 5c8a8dbd7e..d5d7afb295 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,6 @@ "unicorn/no-await-expression-member": "warn", // Annoying sometimes, let's try it "@typescript-eslint/consistent-type-assertions": "warn", - "@typescript-eslint/no-implicit-any-catch": "warn", "jsx-a11y/click-events-have-key-events": "warn", "jsx-a11y/no-static-element-interactions": "warn", diff --git a/src/Globals.d.ts b/src/Globals.d.ts index 09e0d7914a..3f42e43aaa 100644 --- a/src/Globals.d.ts +++ b/src/Globals.d.ts @@ -53,3 +53,18 @@ interface HTMLDialogElement extends HTMLElement { declare const jsdom: { reconfigure: (options: { url: string }) => void; }; + +// `useUnknownInCatchVariables` for .catch method https://github.com/microsoft/TypeScript/issues/45602 +interface Promise { + /** + * Attaches a callback for only the rejection of the Promise. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch( + onrejected?: + | ((reason: unknown) => TResult | PromiseLike) + | undefined + | null + ): Promise; +} diff --git a/src/actionPanel/native.tsx b/src/actionPanel/native.tsx index 4290240aae..4084de6233 100644 --- a/src/actionPanel/native.tsx +++ b/src/actionPanel/native.tsx @@ -126,7 +126,7 @@ export function showActionPanel(callbacks = extensionCallbacks): string { for (const callback of callbacks) { try { callback(); - } catch (error: unknown) { + } catch (error) { // The callbacks should each have their own error handling. But wrap in a try-catch to ensure running // the callbacks does not interfere prevent showing the sidebar reportError(error); diff --git a/src/actionPanel/protocol.tsx b/src/actionPanel/protocol.tsx index 13540169ae..9b9a3c0710 100644 --- a/src/actionPanel/protocol.tsx +++ b/src/actionPanel/protocol.tsx @@ -74,7 +74,7 @@ function runListeners( // @ts-expect-error `data` is a intersection type instead of an union. TODO: Fix or rewrite // eslint-disable-next-line security/detect-object-injection -- method is keyof StoreListener listener[method](data); - } catch (error: unknown) { + } catch (error) { reportError(error); } } diff --git a/src/background/__mocks__/protocol.ts b/src/background/__mocks__/protocol.ts index b9dcbc4b53..74a9443cba 100644 --- a/src/background/__mocks__/protocol.ts +++ b/src/background/__mocks__/protocol.ts @@ -54,7 +54,7 @@ export function liftBackground< try { handlerResult = await method(...args); - } catch (error: unknown) { + } catch (error) { console.log("Error running method", error); handlerResult = toErrorResponse(fullType, error); } diff --git a/src/background/auth.ts b/src/background/auth.ts index c3d7da95a1..52942ed1df 100644 --- a/src/background/auth.ts +++ b/src/background/auth.ts @@ -307,7 +307,7 @@ async function codeGrantFlow( "Content-Type": "application/x-www-form-urlencoded", }, }); - } catch (error: unknown) { + } catch (error) { console.error(error); throw new Error(`Error getting OAuth2 token: ${getErrorMessage(error)}`); } diff --git a/src/background/browserAction.ts b/src/background/browserAction.ts index b292c3129a..9f79dd5c06 100644 --- a/src/background/browserAction.ts +++ b/src/background/browserAction.ts @@ -54,7 +54,7 @@ async function handleBrowserAction(tab: Tabs.Tab): Promise { tabId: tab.id, frameId: TOP_LEVEL_FRAME_ID, }); - } catch (error: unknown) { + } catch (error) { await showErrorInOptions("ERR_BROWSER_ACTION_TOGGLE", tab.index); console.error(error); reportError(error); diff --git a/src/background/contextMenus.ts b/src/background/contextMenus.ts index a8d6bd7313..3c5e663138 100644 --- a/src/background/contextMenus.ts +++ b/src/background/contextMenus.ts @@ -72,7 +72,7 @@ async function dispatchMenu( try { reportEvent("ContextMenuClick", { extensionId: info.menuItemId }); - } catch (error: unknown) { + } catch (error) { console.warn("Error reporting ContextMenuClick event", { error }); } @@ -96,7 +96,7 @@ async function dispatchMenu( message: "Ran content menu item action", className: "success", }); - } catch (error: unknown) { + } catch (error) { if (hasCancelRootCause(error)) { void showNotification(target, { message: "The action was cancelled", @@ -145,7 +145,7 @@ export async function uninstallContextMenu({ console.debug(`Uninstalled context menu ${extensionId}`); return true; - } catch (error: unknown) { + } catch (error) { // Will throw if extensionId doesn't refer to a context menu. The callers don't have an easy way to check the type // without having to resolve the extensionPointId. So instead we'll just expect some of the calls to fail. console.debug("Could not uninstall context menu %s", extensionId, { @@ -193,7 +193,7 @@ export async function ensureContextMenu({ try { await browser.contextMenus.update(menuId, updateProperties); return; - } catch (error: unknown) { + } catch (error) { console.debug("Cannot update context menu", { error }); } } else { @@ -225,7 +225,7 @@ export async function ensureContextMenu({ }); extensionMenuItems.set(extensionId, menuId); - } catch (error: unknown) { + } catch (error) { if ( getErrorMessage(error).includes("Cannot create item with duplicate id") ) { diff --git a/src/background/deployment.ts b/src/background/deployment.ts index e4dba6323d..4d1ba53ba8 100644 --- a/src/background/deployment.ts +++ b/src/background/deployment.ts @@ -197,7 +197,7 @@ async function updateDeployments() { // Fetch the current brick definitions, which will have the current permissions and extensionVersion requirements try { await refreshRegistries(); - } catch (error: unknown) { + } catch (error) { reportError(error); await browser.runtime.openOptionsPage(); // Bail and open the main options page, which 1) fetches the latest bricks, and 2) will prompt the user the to @@ -237,7 +237,7 @@ async function updateDeployments() { console.info( `Applied automatic updates for ${automatic.length} deployment(s)` ); - } catch (error: unknown) { + } catch (error) { reportError(error); automaticError = error; } diff --git a/src/background/devtools/external.ts b/src/background/devtools/external.ts index f829f5258e..19e39c543c 100644 --- a/src/background/devtools/external.ts +++ b/src/background/devtools/external.ts @@ -100,7 +100,7 @@ export async function callBackground( if (isNotification(options)) { try { port.postMessage(message); - } catch (error: unknown) { + } catch (error) { throw new Error( `Error sending devtools notification: ${getErrorMessage(error)}` ); @@ -110,7 +110,7 @@ export async function callBackground( devtoolsHandlers.set(nonce, [resolve, reject]); try { port.postMessage(message); - } catch (error: unknown) { + } catch (error) { reject( new Error(`Error sending devtools message: ${getErrorMessage(error)}`) ); diff --git a/src/background/devtools/internal.ts b/src/background/devtools/internal.ts index ecc9e53dca..2e993b114e 100644 --- a/src/background/devtools/internal.ts +++ b/src/background/devtools/internal.ts @@ -87,7 +87,7 @@ function backgroundMessageListener( let responded = false; if (notification) { - handlerPromise.catch((error: unknown) => { + handlerPromise.catch((error) => { console.warn( `An error occurred when handling notification ${type} (nonce: ${meta?.nonce})`, error @@ -185,7 +185,7 @@ export function liftBackground< async function resetTab(tabId: number): Promise { try { await clearDynamicElements({ tabId, frameId: TOP_LEVEL_FRAME_ID }, {}); - } catch (error: unknown) { + } catch (error) { console.warn("Error clearing dynamic elements for tab: %d", tabId, { error, }); @@ -280,7 +280,7 @@ async function attemptTemporaryAccess({ try { await ensureContentScript({ tabId, frameId }); - } catch (error: unknown) { + } catch (error) { if (isPrivatePageError(error)) { return; } diff --git a/src/background/executor.ts b/src/background/executor.ts index 9fca7b479e..dd267bcca9 100644 --- a/src/background/executor.ts +++ b/src/background/executor.ts @@ -338,7 +338,7 @@ async function retrySend Promise>( try { // eslint-disable-next-line no-await-in-loop -- retry loop return await send(); - } catch (error: unknown) { + } catch (error) { const message = getErrorMessage(error); if (NOT_READY_PARTIAL_MESSAGES.some((query) => message.includes(query))) { diff --git a/src/background/protocol.ts b/src/background/protocol.ts index 87883c9c37..f1006e6e6a 100644 --- a/src/background/protocol.ts +++ b/src/background/protocol.ts @@ -71,7 +71,7 @@ async function handleRequest( `Handler FULFILLED action ${type} (nonce: ${meta?.nonce}, tab: ${sender.tab?.id}, frame: ${sender.frameId})` ); return value; - } catch (error: unknown) { + } catch (error) { if (isNotification(options)) { console.warn( `An error occurred when handling notification ${type} (nonce: ${meta?.nonce}, tab: ${sender.tab?.id}, frame: ${sender.frameId})`, @@ -114,7 +114,7 @@ async function callBackground( console.debug(`Sending background notification ${type} (nonce: ${nonce})`, { extensionId, }); - sendMessage(extensionId, message, {}).catch((error: unknown) => { + sendMessage(extensionId, message, {}).catch((error) => { console.warn( `An error occurred processing background notification ${type} (nonce: ${nonce})`, error @@ -127,7 +127,7 @@ async function callBackground( let response; try { response = await sendMessage(extensionId, message, {}); - } catch (error: unknown) { + } catch (error) { console.debug( `Error sending background action ${type} (nonce: ${nonce})`, { extensionId, error } diff --git a/src/background/proxyService.test.ts b/src/background/proxyService.test.ts index 635ae360c4..5656a0443b 100644 --- a/src/background/proxyService.test.ts +++ b/src/background/proxyService.test.ts @@ -117,7 +117,7 @@ describe("unauthenticated direct requests", () => { try { await proxyService(null, requestConfig); fail("Expected proxyService to throw a RemoteServiceError error"); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(RemoteServiceError); const { status } = (error as RemoteServiceError).response; expect(status).toEqual(500); @@ -149,7 +149,7 @@ describe("authenticated direct requests", () => { try { await proxyService(directServiceConfig, requestConfig); fail("Expected proxyService to throw an error"); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(ContextError); const { status } = ((error as ContextError).cause as AxiosError).response; expect(status).toEqual(403); @@ -191,7 +191,7 @@ describe("proxy service requests", () => { try { await proxyService(proxiedServiceConfig, requestConfig); fail("Expected proxyService to throw an error"); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(ContextError); const { status, statusText } = ((error as ContextError) .cause as AxiosError).response; @@ -208,7 +208,7 @@ describe("proxy service requests", () => { try { await proxyService(proxiedServiceConfig, requestConfig); fail("Expected proxyService to throw an error"); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(Error); expect((error as Error).message).toEqual( "API proxy error: Request failed with status code 500" diff --git a/src/background/requests.ts b/src/background/requests.ts index ff4f38b8ba..3d2052d9d6 100644 --- a/src/background/requests.ts +++ b/src/background/requests.ts @@ -109,7 +109,7 @@ const backgroundRequest = liftBackground( async (config: AxiosRequestConfig) => { try { return cleanResponse(await axios(config)); - } catch (error: unknown) { + } catch (error) { if (isAxiosError(error)) { // Axios offers its own serialization method, but it doesn't include the response. // By deleting toJSON, the serialize-error library will use its default serialization @@ -212,7 +212,7 @@ async function proxyRequest( proxyResponse = (await backgroundRequest( authenticatedRequestConfig )) as SanitizedResponse; - } catch (error: unknown) { + } catch (error) { // If there's a server error with the proxy server itself, we'll also see it in the Rollbar logs for the server. throw new Error(`API proxy error: ${getErrorMessage(error)}`); } @@ -254,7 +254,7 @@ const _proxyService = liftBackground( return await backgroundRequest( await authenticate(serviceConfig, requestConfig) ); - } catch (error: unknown) { + } catch (error) { // Try again - have the user login again, or automatically try to get a new token if ( isAxiosError(error) && @@ -309,7 +309,7 @@ export async function proxyService( return (await backgroundRequest( requestConfig )) as SanitizedResponse; - } catch (error: unknown) { + } catch (error) { if (!isAxiosError(error)) { throw error; } @@ -331,7 +331,7 @@ export async function proxyService( serviceConfig, requestConfig )) as RemoteResponse; - } catch (error: unknown) { + } catch (error) { throw new ContextError(selectError(error) as Error, { serviceId: serviceConfig.serviceId, authId: serviceConfig.id, diff --git a/src/background/telemetry.ts b/src/background/telemetry.ts index 07d2fd90cc..6fd3aa25f4 100644 --- a/src/background/telemetry.ts +++ b/src/background/telemetry.ts @@ -131,7 +131,7 @@ async function userSummary() { .length; numActiveExtensionPoints = uniq(extensions.map((x) => x.extensionPointId)) .length; - } catch (error: unknown) { + } catch (error) { console.warn("Cannot get number of extensions", { error }); } diff --git a/src/baseRegistry.ts b/src/baseRegistry.ts index ef29d901b0..b6c56846f9 100644 --- a/src/baseRegistry.ts +++ b/src/baseRegistry.ts @@ -144,7 +144,7 @@ export class Registry< private parse(raw: unknown): Item | undefined { try { return this.deserialize(raw); - } catch (error: unknown) { + } catch (error) { console.warn( "Error de-serializing item: %s", getErrorMessage(error), diff --git a/src/blocks/effects/wait.ts b/src/blocks/effects/wait.ts index 47e0cde330..f84cd4c533 100644 --- a/src/blocks/effects/wait.ts +++ b/src/blocks/effects/wait.ts @@ -108,7 +108,7 @@ export class WaitElementEffect extends Effect { const [promise, cancel] = awaitElementOnce(selector); try { await runInMillis(async () => promise, maxWaitMillis); - } catch (error: unknown) { + } catch (error) { cancel(); if (error instanceof TimeoutError) { diff --git a/src/blocks/renderers/common.ts b/src/blocks/renderers/common.ts index 16aba8f5c3..d19e808760 100644 --- a/src/blocks/renderers/common.ts +++ b/src/blocks/renderers/common.ts @@ -57,7 +57,7 @@ export async function errorBoundary( // TODO: validate the shape of the value returned return value; - } catch (error: unknown) { + } catch (error) { logger.error(error); const escapedMessage = escape(getErrorMessage(error)); return sanitize(`
An error occurred: ${escapedMessage}
`); diff --git a/src/blocks/renderers/customForm.tsx b/src/blocks/renderers/customForm.tsx index 5ad30a6f44..bc7dd15668 100644 --- a/src/blocks/renderers/customForm.tsx +++ b/src/blocks/renderers/customForm.tsx @@ -104,7 +104,7 @@ export class CustomFormRenderer extends Renderer { className: "success", }, }); - } catch (error: unknown) { + } catch (error) { reportError(error); notifyResult(logger.context.extensionId, { message: "Error saving record", diff --git a/src/blocks/transformers/ephemeralForm/formTransformer.ts b/src/blocks/transformers/ephemeralForm/formTransformer.ts index ca7de64b9c..14dccc8412 100644 --- a/src/blocks/transformers/ephemeralForm/formTransformer.ts +++ b/src/blocks/transformers/ephemeralForm/formTransformer.ts @@ -34,7 +34,6 @@ import { hideActionPanelForm, } from "@/actionPanel/native"; import { showModal } from "@/blocks/transformers/ephemeralForm/modalUtils"; -import { unary } from "lodash"; import { reportError } from "@/telemetry/logging"; import pDefer from "p-defer"; @@ -160,7 +159,7 @@ export class FormTransformer extends Transformer { // In the future we might creating/sending a closeIfEmpty message to the sidebar, so that it would close // if this form was the only entry in the panel hideActionPanelForm(nonce); - void cancelForm(nonce).catch(unary(reportError)); + void cancelForm(nonce).catch(reportError); }); } else { showModal(frameSrc, controller.signal); diff --git a/src/blocks/transformers/jq.ts b/src/blocks/transformers/jq.ts index e8b9e581b1..cb4853f8b8 100644 --- a/src/blocks/transformers/jq.ts +++ b/src/blocks/transformers/jq.ts @@ -69,7 +69,7 @@ export class JQTransformer extends Transformer { try { // eslint-disable-next-line @typescript-eslint/return-await -- Type is `any`, it throws the rule off return await jq.promised.json(input, filter); - } catch (error: unknown) { + } catch (error) { if (!isErrorObject(error) || !error.message.includes("compile error")) { throw error; } diff --git a/src/components/AsyncIcon.tsx b/src/components/AsyncIcon.tsx index 13c42b865b..f54f2d1c4e 100644 --- a/src/components/AsyncIcon.tsx +++ b/src/components/AsyncIcon.tsx @@ -9,7 +9,7 @@ async function handleIconImport( try { const { definition } = await moduleImport; return definition; - } catch (error: unknown) { + } catch (error) { console.warn("Error importing FontAwesome icon library module", { error }); throw error; } diff --git a/src/components/ellipsisMenu/EllipsisMenu.tsx b/src/components/ellipsisMenu/EllipsisMenu.tsx index f67a1df4b4..76893ee911 100644 --- a/src/components/ellipsisMenu/EllipsisMenu.tsx +++ b/src/components/ellipsisMenu/EllipsisMenu.tsx @@ -57,7 +57,7 @@ const EllipsisMenu: React.FunctionComponent<{ // hence no other element knows that the click happened. // Simulating the click on the body will let other menus know user clicked somewhere. document.body.click(); - } catch (error: unknown) { + } catch (error) { console.debug( "EllipsisMenu. Failed to trigger closing other menus", error diff --git a/src/contentScript.ts b/src/contentScript.ts index 3f47035539..15822b3dec 100644 --- a/src/contentScript.ts +++ b/src/contentScript.ts @@ -73,7 +73,7 @@ async function init(): Promise { try { await handleNavigate(); - } catch (error: unknown) { + } catch (error) { console.error("Error initializing contentScript", error); throw error; } @@ -88,7 +88,7 @@ async function init(): Promise { // Informs the standard background listener to track this tab await markTabAsReady(); console.info(`contentScript ready in ${Date.now() - start}ms`); - } catch (error: unknown) { + } catch (error) { console.error("Error pinging the background script", error); throw error; } diff --git a/src/contentScript/devTools.ts b/src/contentScript/devTools.ts index 2929e19d6f..5b38c8ff9d 100644 --- a/src/contentScript/devTools.ts +++ b/src/contentScript/devTools.ts @@ -40,7 +40,7 @@ import { $safeFind } from "@/helpers"; async function read(factory: () => Promise): Promise { try { return await factory(); - } catch (error: unknown) { + } catch (error) { if (deserializeError(error).name === "ComponentNotFoundError") { return "Component not detected"; } diff --git a/src/contentScript/executor.ts b/src/contentScript/executor.ts index 73ac12077f..fb0a5488e1 100644 --- a/src/contentScript/executor.ts +++ b/src/contentScript/executor.ts @@ -54,7 +54,7 @@ export async function runBlockInContentScript(request: RunBlock) { logger, root: document, }); - } catch (error: unknown) { + } catch (error) { // Provide extra logging on the tab because `handlers` doesn't report errors. It's also nice to log here because // we still have the original (non-serialized) error console.info("Error running remote block on tab", { diff --git a/src/contentScript/externalProtocol.ts b/src/contentScript/externalProtocol.ts index a11263bdd3..99b1e65314 100644 --- a/src/contentScript/externalProtocol.ts +++ b/src/contentScript/externalProtocol.ts @@ -114,7 +114,7 @@ async function onContentScriptReceiveMessage( } if (!options.asyncResponse) { - void handler(...payload).catch((error: unknown) => { + void handler(...payload).catch((error) => { console.warn(`${type}: ${meta.nonce}: Notification error`, error); }); } @@ -126,7 +126,7 @@ async function onContentScriptReceiveMessage( try { response.payload = await handler(...payload); console.debug(`${type}: ${meta.nonce}: Handler success`); - } catch (error: unknown) { + } catch (error) { response.payload = toErrorResponse(type, error); console.warn(`${type}: ${meta.nonce}: Handler error`, error); } diff --git a/src/contentScript/lifecycle.ts b/src/contentScript/lifecycle.ts index 4054828d44..55c1577a02 100644 --- a/src/contentScript/lifecycle.ts +++ b/src/contentScript/lifecycle.ts @@ -71,7 +71,7 @@ async function runExtensionPoint( try { installed = await extensionPoint.install(); - } catch (error: unknown) { + } catch (error) { if (error instanceof PromiseCancelled) { console.debug( `Skipping ${extensionPoint.id} because user navigated away from the page` @@ -161,7 +161,7 @@ export function clearDynamic( extensionPoint.uninstall({ global: true }); actionPanel.removeExtensionPoint(extensionPoint.id); markUninstalled(extensionPoint.id); - } catch (error: unknown) { + } catch (error) { reportError(error); } } @@ -246,7 +246,7 @@ async function loadExtensions() { // We cleared _extensionPoints prior to the loop, so we can just push w/o checking if it's already in the array _extensionPoints.push(extensionPoint); } - } catch (error: unknown) { + } catch (error) { console.warn(`Error adding extension point: ${extensionPointId}`, { error, }); @@ -341,7 +341,7 @@ export async function handleNavigate({ // Don't await each extension point since the extension point may never appear. For example, an // extension point that runs on the contact information modal on LinkedIn const runPromise = runExtensionPoint(extensionPoint, cancel).catch( - (error: unknown) => { + (error) => { console.error(`Error installing/running: ${extensionPoint.id}`, { error, }); diff --git a/src/contentScript/pipelineProtocol.ts b/src/contentScript/pipelineProtocol.ts index b666847c66..3d078bffbd 100644 --- a/src/contentScript/pipelineProtocol.ts +++ b/src/contentScript/pipelineProtocol.ts @@ -49,7 +49,7 @@ export async function runRendererPipeline({ } ); throw new BusinessError("Pipeline does not include a renderer"); - } catch (error: unknown) { + } catch (error) { if (error instanceof HeadlessModeError) { return { key: nonce, diff --git a/src/contrib/google/auth.ts b/src/contrib/google/auth.ts index 41398679c0..6ed65db8f0 100644 --- a/src/contrib/google/auth.ts +++ b/src/contrib/google/auth.ts @@ -42,7 +42,7 @@ export async function ensureAuth( gapi.auth.setToken({ access_token: token } as any); return token; } - } catch (error: unknown) { + } catch (error) { throw new Error(`Cannot get Chrome OAuth token: ${getErrorMessage(error)}`); } diff --git a/src/contrib/google/bigquery/handlers.ts b/src/contrib/google/bigquery/handlers.ts index 024f4f3aa9..36c3c54afe 100644 --- a/src/contrib/google/bigquery/handlers.ts +++ b/src/contrib/google/bigquery/handlers.ts @@ -41,7 +41,7 @@ async function ensureBigQuery(): Promise { // https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md try { await gapi.client.load("bigquery", "v2"); - } catch (error: unknown) { + } catch (error) { console.debug("Error fetching BigQuery API definition", { error, }); @@ -62,7 +62,7 @@ export const readQuery = liftBackground( alt: "json", resource, }); - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } diff --git a/src/contrib/google/sheets/FileWidget.tsx b/src/contrib/google/sheets/FileWidget.tsx index a3837fa953..cef807e51f 100644 --- a/src/contrib/google/sheets/FileWidget.tsx +++ b/src/contrib/google/sheets/FileWidget.tsx @@ -79,7 +79,7 @@ const FileWidget: React.FC = ({ doc, onSelect, ...props }) => { } else { onSelect(null); } - } catch (error: unknown) { + } catch (error) { if (!isMounted()) return; onSelect(null); setSheetError(error); @@ -141,7 +141,7 @@ const FileWidget: React.FC = ({ doc, onSelect, ...props }) => { ) .build(); picker.setVisible(true); - } catch (error: unknown) { + } catch (error) { notify.error(`Error loading file picker: ${getErrorMessage(error)}`, { error, }); diff --git a/src/contrib/google/sheets/append.ts b/src/contrib/google/sheets/append.ts index b6bbd6e708..0b9c52e3ea 100644 --- a/src/contrib/google/sheets/append.ts +++ b/src/contrib/google/sheets/append.ts @@ -151,7 +151,7 @@ export class GoogleSheetsAppend extends Effect { console.debug( `Found headers for ${tabName}: ${currentHeaders.join(", ")}` ); - } catch (error: unknown) { + } catch (error) { logger.warn(`Error retrieving headers: ${getErrorMessage(error)}`, { error, }); diff --git a/src/contrib/google/sheets/handlers.ts b/src/contrib/google/sheets/handlers.ts index 9e36bf1cbe..eff9d58a57 100644 --- a/src/contrib/google/sheets/handlers.ts +++ b/src/contrib/google/sheets/handlers.ts @@ -50,7 +50,7 @@ export async function createTab(spreadsheetId: string, tabName: string) { ], }, })) as BatchUpdateSpreadsheetResponse; - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } @@ -71,7 +71,7 @@ export async function appendRows( values, }, })) as AppendValuesResponse; - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } @@ -85,7 +85,7 @@ export async function batchUpdate(spreadsheetId: string, requests: any[]) { requests, }, })) as BatchUpdateSpreadsheetResponse; - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } @@ -109,7 +109,7 @@ export async function batchGet( } }); }); - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } @@ -148,7 +148,7 @@ export async function getSheetProperties( } return spreadsheet.properties; - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } @@ -185,7 +185,7 @@ export async function getTabNames(spreadsheetId: string): Promise { } return spreadsheet.sheets.map((x) => x.properties.title); - } catch (error: unknown) { + } catch (error) { throw await handleRejection(token, error); } } diff --git a/src/contrib/uipath/LocalProcessOptions.tsx b/src/contrib/uipath/LocalProcessOptions.tsx index 11e1134ac2..493c5f5670 100644 --- a/src/contrib/uipath/LocalProcessOptions.tsx +++ b/src/contrib/uipath/LocalProcessOptions.tsx @@ -49,7 +49,7 @@ function useLocalRobot() { const { available, consentCode } = await initRobot(thisTab); setConsentCode(consentCode); setRobotAvailable(available); - } catch (error: unknown) { + } catch (error) { setInitError(error); } }, [port, setConsentCode, setRobotAvailable, setInitError]); diff --git a/src/devTools/Locator.tsx b/src/devTools/Locator.tsx index d1a84c5983..f03e1c3e94 100644 --- a/src/devTools/Locator.tsx +++ b/src/devTools/Locator.tsx @@ -41,7 +41,7 @@ function useSearchWindow(query: string): [unknown[] | null, unknown | null] { const { results } = await searchWindow(thisTab, query); if (!isMounted()) return; setResults(results); - } catch (error: unknown) { + } catch (error) { if (!isMounted()) return; setError(error); } diff --git a/src/devTools/ScopeSettings.tsx b/src/devTools/ScopeSettings.tsx index 28debd820b..a152359b1e 100644 --- a/src/devTools/ScopeSettings.tsx +++ b/src/devTools/ScopeSettings.tsx @@ -54,7 +54,7 @@ const ScopeSettings: React.FunctionComponent = () => { ) => { try { await (await getLinkedApiClient()).patch("/api/settings/", values); - } catch (error: unknown) { + } catch (error) { if (!isAxiosError(error)) { notify.error("Error updating account alias", { error, diff --git a/src/devTools/context.ts b/src/devTools/context.ts index cc16b40a18..96b359b519 100644 --- a/src/devTools/context.ts +++ b/src/devTools/context.ts @@ -137,7 +137,7 @@ async function connectToFrame(): Promise { async () => detectFrameworks(thisTab, null), 500 ); - } catch (error: unknown) { + } catch (error) { console.debug(`connectToFrame: error detecting frameworks ${url}`, { error, }); @@ -178,7 +178,7 @@ export function useDevConnection(): Context { hasPermissions: true, meta, }); - } catch (error: unknown) { + } catch (error) { if (error instanceof PermissionsError) { setCurrent({ ...common, diff --git a/src/devTools/editor/ElementWizard.tsx b/src/devTools/editor/ElementWizard.tsx index f92496ab2a..2ef6d6ff41 100644 --- a/src/devTools/editor/ElementWizard.tsx +++ b/src/devTools/editor/ElementWizard.tsx @@ -115,7 +115,7 @@ const ElementWizard: React.FunctionComponent<{ const onSave = async () => { try { await save(); - } catch (error: unknown) { + } catch (error) { setStatus(error); } }; diff --git a/src/devTools/editor/fields/SelectorSelectorWidget.tsx b/src/devTools/editor/fields/SelectorSelectorWidget.tsx index 4cc572ff8a..58eb4aa9a8 100644 --- a/src/devTools/editor/fields/SelectorSelectorWidget.tsx +++ b/src/devTools/editor/fields/SelectorSelectorWidget.tsx @@ -170,7 +170,7 @@ const SelectorSelectorWidget: React.FC = ({ console.debug("Setting selector", { selected, firstSelector }); setValue(firstSelector); - } catch (error: unknown) { + } catch (error) { notify.error(`Error selecting element: ${getErrorMessage(error)}`, { error, }); diff --git a/src/devTools/editor/hooks/useAddElement.ts b/src/devTools/editor/hooks/useAddElement.ts index 360aee2913..8c086441c4 100644 --- a/src/devTools/editor/hooks/useAddElement.ts +++ b/src/devTools/editor/hooks/useAddElement.ts @@ -71,7 +71,7 @@ function useAddElement(): AddElement { ); dispatch(actions.addElement(initialState as FormState)); - } catch (error: unknown) { + } catch (error) { if (getErrorMessage(error) === "Selection cancelled") { return; } diff --git a/src/devTools/editor/hooks/useCreate.ts b/src/devTools/editor/hooks/useCreate.ts index 884f4ae259..c9b3c72ee6 100644 --- a/src/devTools/editor/hooks/useCreate.ts +++ b/src/devTools/editor/hooks/useCreate.ts @@ -146,7 +146,7 @@ function useCreate(): CreateCallback { try { await ensurePermissions(element, addToast); - } catch (error: unknown) { + } catch (error) { // Continue to allow saving (because there's a workaround) reportError(error); console.error("Error checking/enabling permissions", { error }); @@ -190,7 +190,7 @@ function useCreate(): CreateCallback { "extensionPoint", extensionPointConfig ); - } catch (error: unknown) { + } catch (error) { return onStepError(error, "saving foundation"); } } @@ -206,7 +206,7 @@ function useCreate(): CreateCallback { blockRegistry.fetch(), extensionPointRegistry.fetch(), ]); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast( `Error fetching remote bricks: ${selectErrorMessage(error)}`, @@ -235,13 +235,13 @@ function useCreate(): CreateCallback { } dispatch(markSaved(element.uuid)); - } catch (error: unknown) { + } catch (error) { return onStepError(error, "saving extension"); } try { await reactivate(); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast( `Error re-activating bricks on page(s): ${selectErrorMessage( @@ -259,7 +259,7 @@ function useCreate(): CreateCallback { autoDismiss: true, }); return null; - } catch (error: unknown) { + } catch (error) { console.error("Error saving extension", { error }); reportError(error); addToast(`Error saving extension: ${getErrorMessage(error)}`, { diff --git a/src/devTools/editor/hooks/useRemove.ts b/src/devTools/editor/hooks/useRemove.ts index 269540239d..c96c90fd18 100644 --- a/src/devTools/editor/hooks/useRemove.ts +++ b/src/devTools/editor/hooks/useRemove.ts @@ -80,11 +80,11 @@ function useRemove(element: FormState): () => void { await clearDynamicElements(thisTab, { uuid: element.uuid, }); - } catch (error: unknown) { + } catch (error) { // Element might not be on the page anymore console.info("Cannot clear dynamic element from page", { error }); } - } catch (error: unknown) { + } catch (error) { reportError(error); addToast(`Error removing element: ${getErrorMessage(error)}`, { appearance: "error", diff --git a/src/devTools/editor/hooks/useReset.ts b/src/devTools/editor/hooks/useReset.ts index 2ae9c7f10f..6eca7fba59 100644 --- a/src/devTools/editor/hooks/useReset.ts +++ b/src/devTools/editor/hooks/useReset.ts @@ -50,7 +50,7 @@ function useReset(): (useResetConfig: Config) => void { const extension = installed.find((x) => x.id === element.uuid); const state = await extensionToFormState(extension); dispatch(actions.resetInstalled(state)); - } catch (error: unknown) { + } catch (error) { reportError(error); dispatch(actions.adapterError({ uuid: element.uuid, error })); } diff --git a/src/devTools/editor/panes/insert/GenericInsertPane.tsx b/src/devTools/editor/panes/insert/GenericInsertPane.tsx index f121cd707e..70f0e16f28 100644 --- a/src/devTools/editor/panes/insert/GenericInsertPane.tsx +++ b/src/devTools/editor/panes/insert/GenericInsertPane.tsx @@ -64,7 +64,7 @@ const GenericInsertPane: React.FunctionComponent<{ // have to manually toggle it void showActionPanel(thisTab); } - } catch (error: unknown) { + } catch (error) { reportError(error); addToast("Error adding element", { autoDismiss: true, @@ -85,7 +85,7 @@ const GenericInsertPane: React.FunctionComponent<{ extensionPoint.rawConfig )) as FormState ); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast("Error using existing foundation", { autoDismiss: true, @@ -105,7 +105,7 @@ const GenericInsertPane: React.FunctionComponent<{ await start( config.fromNativeElement(url, metadata, undefined, []) as FormState ); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast("Error using adding new element", { autoDismiss: true, diff --git a/src/devTools/editor/panes/insert/useAddExisting.ts b/src/devTools/editor/panes/insert/useAddExisting.ts index a7c577df1c..91f0451776 100644 --- a/src/devTools/editor/panes/insert/useAddExisting.ts +++ b/src/devTools/editor/panes/insert/useAddExisting.ts @@ -52,7 +52,7 @@ function useAddExisting( }); dispatch(addElement(state as FormState)); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast(`Error adding ${config.label}`, { autoDismiss: true, diff --git a/src/devTools/editor/panes/save/useSavingWizard.test.tsx b/src/devTools/editor/panes/save/useSavingWizard.test.tsx index 68e7a268a4..2fc87c22c7 100644 --- a/src/devTools/editor/panes/save/useSavingWizard.test.tsx +++ b/src/devTools/editor/panes/save/useSavingWizard.test.tsx @@ -100,7 +100,7 @@ test("maintains wizard open state", () => { // Save will open the modal window. // Should not await for the promise to resolve to check that window is open. act(() => { - void result.current.save().catch((error: unknown) => { + void result.current.save().catch((error) => { // Got an error, failing the test console.error(error); expect(error).toBeUndefined(); @@ -134,7 +134,7 @@ test("saves non recipe element", async () => { const { result } = renderUseSavingWizard(store); act(() => { - result.current.save().catch((error: unknown) => { + result.current.save().catch((error) => { // Got an error, failing the test console.error(error); expect(error).toBeUndefined(); @@ -212,7 +212,7 @@ describe("saving a Recipe Extension", () => { // Get into the saving process act(() => { - void result.current.save().catch((error: unknown) => { + void result.current.save().catch((error) => { // Got an error, failing the test console.error(error); expect(error).toBeUndefined(); @@ -337,7 +337,7 @@ describe("saving a Recipe Extension", () => { try { await creatingRecipePromise; await savingPromise; - } catch (error: unknown) { + } catch (error) { expect(error).toBe("Failed to create new Blueprint"); } @@ -426,7 +426,7 @@ describe("saving a Recipe Extension", () => { try { await updatingRecipePromise; await savingPromise; - } catch (error: unknown) { + } catch (error) { expect(error).toBe("Failed to update the Blueprint"); } diff --git a/src/devTools/editor/sidebar/InstalledEntry.tsx b/src/devTools/editor/sidebar/InstalledEntry.tsx index c3cb1853f5..617fd0e685 100644 --- a/src/devTools/editor/sidebar/InstalledEntry.tsx +++ b/src/devTools/editor/sidebar/InstalledEntry.tsx @@ -50,7 +50,7 @@ const InstalledEntry: React.FunctionComponent<{ try { const state = await extensionToFormState(extension); dispatch(actions.selectInstalled(state)); - } catch (error: unknown) { + } catch (error) { reportError(error); dispatch(actions.adapterError({ uuid: extension.id, error })); } diff --git a/src/devTools/editor/tabs/effect/BlockPreview.tsx b/src/devTools/editor/tabs/effect/BlockPreview.tsx index e826736b49..10fd714d77 100644 --- a/src/devTools/editor/tabs/effect/BlockPreview.tsx +++ b/src/devTools/editor/tabs/effect/BlockPreview.tsx @@ -162,7 +162,7 @@ const BlockPreview: React.FunctionComponent<{ context: { ...context, ...(await makeServiceContext(services)) }, }); dispatch(previewSlice.actions.setSuccess({ output, outputKey })); - } catch (error: unknown) { + } catch (error) { dispatch(previewSlice.actions.setError({ error })); } }, diff --git a/src/devTools/editor/tabs/effect/ExtensionPointPreview.tsx b/src/devTools/editor/tabs/effect/ExtensionPointPreview.tsx index d014d30008..0443d6b1f4 100644 --- a/src/devTools/editor/tabs/effect/ExtensionPointPreview.tsx +++ b/src/devTools/editor/tabs/effect/ExtensionPointPreview.tsx @@ -94,7 +94,7 @@ const ExtensionPointPreview: React.FunctionComponent<{ rootSelector ); dispatch(previewSlice.actions.runSuccess({ "@input": data })); - } catch (error: unknown) { + } catch (error) { dispatch(previewSlice.actions.runError(error)); } }, []); diff --git a/src/devTools/protocol.ts b/src/devTools/protocol.ts index e26259b062..4a3e2fe2a5 100644 --- a/src/devTools/protocol.ts +++ b/src/devTools/protocol.ts @@ -37,7 +37,7 @@ export async function connectDevtools(): Promise { let port: Runtime.Port; try { port = await runtimeConnect(PORT_NAME); - } catch (error: unknown) { + } catch (error) { // Not helpful to use recordError here because it can't connect to the background page to send // the error telemetry console.error("Devtools cannot connect to the background page", { diff --git a/src/devtools.ts b/src/devtools.ts index 7fdcb2f964..2b6ef2f52d 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -35,7 +35,7 @@ async function updateElementProperties(): Promise { try { await updateSelectedElement(); await sidebar.setObject(await readSelected(thisTab)); - } catch (error: unknown) { + } catch (error) { await sidebar.setObject({ error: serializeError(error) }); } } diff --git a/src/extensionPoints/actionPanelExtension.ts b/src/extensionPoints/actionPanelExtension.ts index 85c452c2f9..5c3ed68d52 100644 --- a/src/extensionPoints/actionPanelExtension.ts +++ b/src/extensionPoints/actionPanelExtension.ts @@ -144,7 +144,7 @@ export abstract class ActionPanelExtensionPoint extends ExtensionPoint { try { await this.runExtension(readerContext, extension); - } catch (error: unknown) { + } catch (error) { errors.push(error); this.logger .childLogger({ diff --git a/src/extensionPoints/contextMenu.ts b/src/extensionPoints/contextMenu.ts index 2f288e6a94..eeda0c6851 100644 --- a/src/extensionPoints/contextMenu.ts +++ b/src/extensionPoints/contextMenu.ts @@ -280,7 +280,7 @@ export abstract class ContextMenuExtensionPoint extends ExtensionPoint { try { await this.registerExtension(extension); - } catch (error: unknown) { + } catch (error) { reportError(error, { deploymentId: extension._deployment?.id, extensionPointId: extension.extensionPointId, @@ -372,7 +372,7 @@ export abstract class ContextMenuExtensionPoint extends ExtensionPoint void): () => void { for (const observer of observers) { try { observer.disconnect(); - } catch (error: unknown) { + } catch (error) { console.warn("Error disconnecting mutation observer", error); } } @@ -86,7 +86,7 @@ export function onNodeRemoved(node: Node, callback: () => void): () => void { for (const observer of observers) { try { observer.disconnect(); - } catch (error: unknown) { + } catch (error) { console.warn("Error disconnecting mutation observer", error); } } diff --git a/src/extensionPoints/menuItemExtension.ts b/src/extensionPoints/menuItemExtension.ts index 2494570e45..09d2d030a7 100644 --- a/src/extensionPoints/menuItemExtension.ts +++ b/src/extensionPoints/menuItemExtension.ts @@ -240,7 +240,7 @@ export abstract class MenuItemExtensionPoint extends ExtensionPoint { try { observer.disconnect(); - } catch (error: unknown) { + } catch (error) { console.error("Error cancelling mutation observer", error); } for (const cancel of cancellers) { try { cancel(); - } catch (error: unknown) { + } catch (error) { console.error("Error cancelling dependency observer", error); } } @@ -702,7 +702,7 @@ export abstract class MenuItemExtensionPoint extends ExtensionPoint { // Running in loop to ensure consistent placement. OK because `installBody` in runExtension is runs asynchronously // eslint-disable-next-line no-await-in-loop await this.runExtension(readerContext, extension); - } catch (error: unknown) { + } catch (error) { errors.push(error); this.logger .childLogger({ diff --git a/src/extensionPoints/triggerExtension.ts b/src/extensionPoints/triggerExtension.ts index 7e5a554244..e5f7bb1165 100644 --- a/src/extensionPoints/triggerExtension.ts +++ b/src/extensionPoints/triggerExtension.ts @@ -259,7 +259,7 @@ export abstract class TriggerExtensionPoint extends ExtensionPoint(factory: () => T): T | null { try { return factory(); - } catch (error: unknown) { + } catch (error) { if ( error instanceof ComponentNotFoundError || error instanceof FrameworkNotFound diff --git a/src/hooks/common.ts b/src/hooks/common.ts index ed3d11ef2c..7fb1e4e42a 100644 --- a/src/hooks/common.ts +++ b/src/hooks/common.ts @@ -92,7 +92,7 @@ export function useAsyncState( ? promiseOrGenerator() : promiseOrGenerator); dispatch(slice.actions.success({ data: promiseResult })); - } catch (error: unknown) { + } catch (error) { dispatch(slice.actions.failure({ error })); } }, [dispatch, promiseOrGenerator]); @@ -105,7 +105,7 @@ export function useAsyncState( : promiseOrGenerator); if (!isMounted()) return; dispatch(slice.actions.success({ data: promiseResult })); - } catch (error: unknown) { + } catch (error) { if (isMounted()) { dispatch(slice.actions.failure({ error })); } diff --git a/src/hooks/fetch.ts b/src/hooks/fetch.ts index 0490eafb2d..559589e246 100644 --- a/src/hooks/fetch.ts +++ b/src/hooks/fetch.ts @@ -49,7 +49,7 @@ export async function fetch( try { const { data } = await client.get(relativeOrAbsoluteUrl); return data; - } catch (error: unknown) { + } catch (error) { if ( isAxiosError(error) && // There are some cases where `response` is undefined (because the browser blocked the request, e.g., b/c CORS) diff --git a/src/hooks/useBlockOptions.ts b/src/hooks/useBlockOptions.ts index 5896975281..8b319b228f 100644 --- a/src/hooks/useBlockOptions.ts +++ b/src/hooks/useBlockOptions.ts @@ -45,7 +45,7 @@ export function useBlockOptions( const block = await blockRegistry.lookup(id); if (!isMounted()) return; setBlock({ block }); - } catch (error: unknown) { + } catch (error) { reportError(error); if (!isMounted()) return; setBlock({ error: String(error) }); diff --git a/src/hooks/useDeployments.ts b/src/hooks/useDeployments.ts index b24a490ec7..c5e56ffcaf 100644 --- a/src/hooks/useDeployments.ts +++ b/src/hooks/useDeployments.ts @@ -195,7 +195,7 @@ function useDeployments(): DeploymentState { // Get the latest brick definitions so we have the latest permission and version requirements // XXX: is this being broadcast to the content scripts so they get the updated brick definition content? await refreshRegistries(); - } catch (error: unknown) { + } catch (error) { // Try to proceed if we can't refresh the brick definitions notify.warning( `Error fetching latest bricks from server: ${getErrorMessage(error)}`, @@ -219,7 +219,7 @@ function useDeployments(): DeploymentState { let accepted = false; try { accepted = await ensureAllPermissions(permissions); - } catch (error: unknown) { + } catch (error) { notify.error(`Error granting permissions: ${getErrorMessage(error)}`, { error, }); @@ -236,7 +236,7 @@ function useDeployments(): DeploymentState { try { activateDeployments(dispatch, deployments, installedExtensions); notify.success("Activated team deployments"); - } catch (error: unknown) { + } catch (error) { notify.error("Error activating team deployments", { error, }); diff --git a/src/hooks/useFetch.ts b/src/hooks/useFetch.ts index 2055148ed3..15fdbd9361 100644 --- a/src/hooks/useFetch.ts +++ b/src/hooks/useFetch.ts @@ -42,7 +42,7 @@ function useFetch( try { const data = await fetch(relativeOrAbsoluteUrl); setData(data); - } catch (error: unknown) { + } catch (error) { setError(error); notify.error("An error occurred fetching data from the server"); } @@ -58,7 +58,7 @@ function useFetch( const data = await fetch(relativeOrAbsoluteUrl); if (!isMounted()) return; setData(data); - } catch (error: unknown) { + } catch (error) { if (!isMounted()) return; setError(error); notify.error("An error occurred fetching data from the server"); diff --git a/src/hooks/useRefresh.ts b/src/hooks/useRefresh.ts index a866559451..0bbe2c9f6d 100644 --- a/src/hooks/useRefresh.ts +++ b/src/hooks/useRefresh.ts @@ -59,7 +59,7 @@ function useRefresh(options?: { async (isMounted = stubTrue) => { try { await refreshRegistries(); - } catch (error: unknown) { + } catch (error) { console.error(error); if (!isMounted()) { return; diff --git a/src/hooks/useUserAction.ts b/src/hooks/useUserAction.ts index 01b65449fe..9c0c8f6554 100644 --- a/src/hooks/useUserAction.ts +++ b/src/hooks/useUserAction.ts @@ -88,7 +88,7 @@ function useUserAction unknown>( } return rv; - } catch (error: unknown) { + } catch (error) { if (error instanceof CancelError) { return; } diff --git a/src/nativeEditor/frameworks.ts b/src/nativeEditor/frameworks.ts index 8f8ddc7515..49c7693248 100644 --- a/src/nativeEditor/frameworks.ts +++ b/src/nativeEditor/frameworks.ts @@ -64,7 +64,7 @@ export async function elementInfo( try { component = adapter.getComponent(element); - } catch (error: unknown) { + } catch (error) { console.debug("Could not get component information", { error }); } diff --git a/src/nativeEditor/infer.ts b/src/nativeEditor/infer.ts index 575e252861..ca98545c68 100644 --- a/src/nativeEditor/infer.ts +++ b/src/nativeEditor/infer.ts @@ -203,7 +203,7 @@ function commonButtonStructure( try { setCommonAttrs($common, $items); - } catch (error: unknown) { + } catch (error) { if (error instanceof SkipElement) { // Shouldn't happen at the top level return [$(), currentCaptioned]; @@ -519,7 +519,7 @@ export function inferSelectors( const makeSelector = (allowed: CssSelectorType[]) => { try { return safeCssSelector(element, allowed, root); - } catch (error: unknown) { + } catch (error) { console.warn("Selector inference failed", { element, allowed, diff --git a/src/options/pages/UpdateBanner.tsx b/src/options/pages/UpdateBanner.tsx index 28a1224465..6abad05b20 100644 --- a/src/options/pages/UpdateBanner.tsx +++ b/src/options/pages/UpdateBanner.tsx @@ -28,7 +28,7 @@ const UpdateBanner: React.FunctionComponent = () => { try { const { installed, available } = await getAvailableVersion(); return available && installed !== available; - } catch (error: unknown) { + } catch (error) { reportError(error); return false; } diff --git a/src/options/pages/activateExtension/ActivateForm.tsx b/src/options/pages/activateExtension/ActivateForm.tsx index f35fe083fb..a3df459898 100644 --- a/src/options/pages/activateExtension/ActivateForm.tsx +++ b/src/options/pages/activateExtension/ActivateForm.tsx @@ -56,7 +56,7 @@ const ActivateForm: React.FunctionComponent<{ ); notify.success("Activated brick"); dispatch(push("/installed")); - } catch (error: unknown) { + } catch (error) { notify.error("Error activating brick", { error, }); diff --git a/src/options/pages/activateExtension/useEnsurePermissions.ts b/src/options/pages/activateExtension/useEnsurePermissions.ts index 79f4af7891..0cfd8559b6 100644 --- a/src/options/pages/activateExtension/useEnsurePermissions.ts +++ b/src/options/pages/activateExtension/useEnsurePermissions.ts @@ -73,7 +73,7 @@ function useEnsurePermissions( try { accepted = await ensureAllPermissions(permissions); - } catch (error: unknown) { + } catch (error) { notify.error(`Error granting permissions: ${getErrorMessage(error)}`, { error, }); diff --git a/src/options/pages/brickEditor/useSubmitBrick.ts b/src/options/pages/brickEditor/useSubmitBrick.ts index 538ed19801..c7ffbd288b 100644 --- a/src/options/pages/brickEditor/useSubmitBrick.ts +++ b/src/options/pages/brickEditor/useSubmitBrick.ts @@ -65,7 +65,7 @@ function useSubmitBrick({ const remove = useCallback(async () => { try { await (await getLinkedApiClient()).delete(url); - } catch (error: unknown) { + } catch (error) { notify.error("Error deleting brick", { error, }); @@ -120,7 +120,7 @@ function useSubmitBrick({ refreshPromise .then(async () => reactivate()) - .catch((error: unknown) => { + .catch((error) => { notify.warning( `Error re-activating bricks: ${getErrorMessage(error)}`, { @@ -135,7 +135,7 @@ function useSubmitBrick({ if (create) { history.push(`/workshop/bricks/${data.id}/`); } - } catch (error: unknown) { + } catch (error) { console.debug("Got validation error", error); if (isAxiosError(error)) { diff --git a/src/options/pages/brickEditor/validate.ts b/src/options/pages/brickEditor/validate.ts index 0fa231070b..d92ba20235 100644 --- a/src/options/pages/brickEditor/validate.ts +++ b/src/options/pages/brickEditor/validate.ts @@ -42,7 +42,7 @@ export async function validateSchema( try { json = loadBrickYaml(value) as PartialSchema; - } catch (error: unknown) { + } catch (error) { return { config: [`Invalid YAML: ${getErrorMessage(error)}`], }; @@ -63,7 +63,7 @@ export async function validateSchema( json as Record, json.kind as keyof typeof KIND_SCHEMAS ); - } catch (error: unknown) { + } catch (error) { console.error("An error occurred when validating the schema", error); return { config: ["An error occurred when validating the schema"] }; } diff --git a/src/options/pages/installed/InstalledPage.tsx b/src/options/pages/installed/InstalledPage.tsx index 738953ec7c..369ec2dd8c 100644 --- a/src/options/pages/installed/InstalledPage.tsx +++ b/src/options/pages/installed/InstalledPage.tsx @@ -222,7 +222,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ dispatch(removeExtension({ extensionId })); // XXX: also remove remove side panel panels that are already open? void uninstallContextMenu({ extensionId }).catch(reportError); - void reactivate().catch((error: unknown) => { + void reactivate().catch((error) => { console.warn("Error re-activating content scripts", { error }); }); }, diff --git a/src/options/pages/installed/ShareExtensionModal.tsx b/src/options/pages/installed/ShareExtensionModal.tsx index 7baed7f683..09a6bac481 100644 --- a/src/options/pages/installed/ShareExtensionModal.tsx +++ b/src/options/pages/installed/ShareExtensionModal.tsx @@ -139,7 +139,7 @@ const ShareExtensionModal: React.FC<{ ); dispatch(push("/installed")); notify.success("Converted/shared brick"); - } catch (error: unknown) { + } catch (error) { if (isAxiosError(error) && error.response.data.config) { helpers.setStatus(error.response.data.config); return; diff --git a/src/options/pages/marketplace/ActivateWizard.tsx b/src/options/pages/marketplace/ActivateWizard.tsx index e836e98ec4..fb15438653 100644 --- a/src/options/pages/marketplace/ActivateWizard.tsx +++ b/src/options/pages/marketplace/ActivateWizard.tsx @@ -82,7 +82,7 @@ const ActivateButton: React.FunctionComponent<{ .then(() => { activate(); }) - .catch((error: unknown) => { + .catch((error) => { notify.error( `Error re-installing bricks: ${getErrorMessage(error)}`, { diff --git a/src/options/pages/marketplace/useEnsurePermissions.ts b/src/options/pages/marketplace/useEnsurePermissions.ts index 105c7e7492..b0349c3d13 100644 --- a/src/options/pages/marketplace/useEnsurePermissions.ts +++ b/src/options/pages/marketplace/useEnsurePermissions.ts @@ -59,7 +59,7 @@ function useEnsurePermissions( try { accepted = await ensureAllPermissions(permissions); - } catch (error: unknown) { + } catch (error) { notify.error(`Error granting permissions: ${getErrorMessage(error)}`, { error, }); diff --git a/src/options/pages/services/PrivateServicesCard.tsx b/src/options/pages/services/PrivateServicesCard.tsx index 421b291f9d..f3db9c0e85 100644 --- a/src/options/pages/services/PrivateServicesCard.tsx +++ b/src/options/pages/services/PrivateServicesCard.tsx @@ -60,7 +60,7 @@ const PrivateServicesCard: React.FunctionComponent = ({ try { await deleteCachedAuth(authId); notify.success("Reset login for integration"); - } catch (error: unknown) { + } catch (error) { notify.error("Error resetting login for integration", { error, }); diff --git a/src/options/pages/services/ServiceEditorModal.tsx b/src/options/pages/services/ServiceEditorModal.tsx index 742abce122..9ffd0e9a9c 100644 --- a/src/options/pages/services/ServiceEditorModal.tsx +++ b/src/options/pages/services/ServiceEditorModal.tsx @@ -107,7 +107,7 @@ const ServiceEditorModal: React.FunctionComponent = ({ try { return buildYup(schema, {}); - } catch (error: unknown) { + } catch (error) { console.error("Error building Yup validator from JSON Schema"); reportError(error); return Yup.object(); diff --git a/src/options/pages/services/ServicesEditor.tsx b/src/options/pages/services/ServicesEditor.tsx index 9f805714b1..349b29183d 100644 --- a/src/options/pages/services/ServicesEditor.tsx +++ b/src/options/pages/services/ServicesEditor.tsx @@ -88,7 +88,7 @@ const ServicesEditor: React.FunctionComponent = ({ try { await refreshBackgroundAuths(); - } catch (error: unknown) { + } catch (error) { notify.warning( "Error refreshing service configurations, restart the PixieBrix extension", { @@ -112,7 +112,7 @@ const ServicesEditor: React.FunctionComponent = ({ try { await refreshBackgroundAuths(); - } catch (error: unknown) { + } catch (error) { notify.warning( "Error refreshing service configurations, restart the PixieBrix extension", { diff --git a/src/options/pages/settings/FactoryResetSettings.tsx b/src/options/pages/settings/FactoryResetSettings.tsx index 275453a5e8..0294dc6163 100644 --- a/src/options/pages/settings/FactoryResetSettings.tsx +++ b/src/options/pages/settings/FactoryResetSettings.tsx @@ -49,7 +49,7 @@ const FactoryResetSettings: React.FunctionComponent<{ appearance: "success", autoDismiss: true, }); - } catch (error: unknown) { + } catch (error) { addToast( `Error resetting options and service configurations: ${getErrorMessage( error diff --git a/src/options/pages/settings/LoggingSettings.tsx b/src/options/pages/settings/LoggingSettings.tsx index 585cf54241..f1404af670 100644 --- a/src/options/pages/settings/LoggingSettings.tsx +++ b/src/options/pages/settings/LoggingSettings.tsx @@ -76,7 +76,7 @@ const LoggingSettings: React.FunctionComponent = () => { appearance: "success", autoDismiss: true, }); - } catch (error: unknown) { + } catch (error) { reportError(error); addToast(`Error clearing local logs: ${getErrorMessage(error)}`, { appearance: "error", diff --git a/src/pageScript/protocol.ts b/src/pageScript/protocol.ts index 003ff79676..b2ccd6ed8d 100644 --- a/src/pageScript/protocol.ts +++ b/src/pageScript/protocol.ts @@ -91,7 +91,7 @@ async function messageHandler(event: MessageEvent): Promise { try { // Chrome will drop the whole detail if it contains non-serializable values, e.g., methods cleanResult = cleanValue(result ?? null); - } catch (error: unknown) { + } catch (error) { console.error("Cannot serialize result", { result, error }); throw new Error(`Cannot serialize result for result ${type}`); } @@ -106,7 +106,7 @@ async function messageHandler(event: MessageEvent): Promise { detail, }) ); - } catch (error: unknown) { + } catch (error) { try { const detail = { id: meta.id, @@ -118,7 +118,7 @@ async function messageHandler(event: MessageEvent): Promise { detail, }) ); - } catch (error_: unknown) { + } catch (error_) { console.error( "An error occurred while dispatching an error for %s", type, diff --git a/src/pages/marketplace/useInstall.ts b/src/pages/marketplace/useInstall.ts index 43933d9845..42243753e2 100644 --- a/src/pages/marketplace/useInstall.ts +++ b/src/pages/marketplace/useInstall.ts @@ -111,7 +111,7 @@ function useInstall(recipe: RecipeDefinition): InstallRecipe { void reactivate(); dispatch(push("/installed")); - } catch (error: unknown) { + } catch (error) { notify.error(`Error installing ${recipe.metadata.name}`, { error, }); diff --git a/src/permissions/index.ts b/src/permissions/index.ts index 106b2bd81b..b466113d97 100644 --- a/src/permissions/index.ts +++ b/src/permissions/index.ts @@ -120,7 +120,7 @@ export async function collectPermissions( extensionPoint, } ); - } catch (error: unknown) { + } catch (error) { console.warn("Error getting blocks for extensionPoint %s", id, { error, config, diff --git a/src/popups/PermissionsPopup.tsx b/src/popups/PermissionsPopup.tsx index bf356b4018..fea84d4822 100644 --- a/src/popups/PermissionsPopup.tsx +++ b/src/popups/PermissionsPopup.tsx @@ -50,7 +50,7 @@ const PermissionsPopup: React.FC = () => { } setRejected(true); - } catch (error: unknown) { + } catch (error) { reportError(error); setError(getErrorMessage(error)); } diff --git a/src/runtime/pathHelpers.ts b/src/runtime/pathHelpers.ts index 6976885cb9..c8a88cc907 100644 --- a/src/runtime/pathHelpers.ts +++ b/src/runtime/pathHelpers.ts @@ -104,7 +104,7 @@ export function getPropByPath( if (typeof value === "function") { try { value = value.apply(previous, args); - } catch (error: unknown) { + } catch (error) { throw new Error( `Error running method ${part}: ${getErrorMessage(error)}` ); diff --git a/src/runtime/pipelineTests/conditional.test.ts b/src/runtime/pipelineTests/conditional.test.ts index cd5f955d2c..4eff0e6bb1 100644 --- a/src/runtime/pipelineTests/conditional.test.ts +++ b/src/runtime/pipelineTests/conditional.test.ts @@ -174,7 +174,7 @@ describe("apiVersion: v2", () => { simpleInput({ inputArg: 42 }), testOptions("v2") ); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(InputValidationError); } }); diff --git a/src/runtime/pipelineTests/deploymentAlert.test.ts b/src/runtime/pipelineTests/deploymentAlert.test.ts index 6545480121..f191728b68 100644 --- a/src/runtime/pipelineTests/deploymentAlert.test.ts +++ b/src/runtime/pipelineTests/deploymentAlert.test.ts @@ -92,7 +92,7 @@ describe.each([["v1"], ["v2"], ["v3"]])( { ...testOptions(apiVersion), logger } ); fail("Expected reducePipeline to throw"); - } catch (error: unknown) { + } catch (error) { serializedError = serializeError((error as ContextError).cause); } diff --git a/src/runtime/pipelineTests/validateInput.test.ts b/src/runtime/pipelineTests/validateInput.test.ts index 3607b07ccf..1467dde1eb 100644 --- a/src/runtime/pipelineTests/validateInput.test.ts +++ b/src/runtime/pipelineTests/validateInput.test.ts @@ -54,7 +54,7 @@ describe("apiVersion: v1", () => { simpleInput({ inputArg: 42 }), testOptions("v1") ); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(InputValidationError); } }); @@ -68,7 +68,7 @@ describe("apiVersion: v1", () => { ]; try { await reducePipeline(pipeline, simpleInput({}), testOptions("v1")); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(InputValidationError); } }); @@ -89,7 +89,7 @@ describe("apiVersion: v2", () => { simpleInput({ inputArg: 42 }), testOptions("v2") ); - } catch (error: unknown) { + } catch (error) { expect(error).toBeInstanceOf(InputValidationError); } }); diff --git a/src/runtime/reducePipeline.ts b/src/runtime/reducePipeline.ts index 9e0dcfd0a1..a369de4ac4 100644 --- a/src/runtime/reducePipeline.ts +++ b/src/runtime/reducePipeline.ts @@ -618,7 +618,7 @@ export async function reducePipeline( ...options, logger: stageLogger, }); - } catch (error: unknown) { + } catch (error) { // Must await because it will throw a wrapped error // eslint-disable-next-line no-await-in-loop -- can't parallelize because each step depends on previous step await throwBlockError(blockConfig, state, error, options); diff --git a/src/script.ts b/src/script.ts index d0598cd8f5..c5cc4ff019 100644 --- a/src/script.ts +++ b/src/script.ts @@ -154,7 +154,7 @@ async function read( try { element = requireSingleElement(selector); - } catch (error: unknown) { + } catch (error) { console.debug("read: error calling requireSingleElement", { error, options, @@ -174,7 +174,7 @@ async function read( retryMillis, predicate: identity, }); - } catch (error: unknown) { + } catch (error) { if (error instanceof TimeoutError) { console.warn( `Could not find framework component for selector ${selector} in ${waitMillis}ms` diff --git a/src/services/api.ts b/src/services/api.ts index f67aa361d5..9451593a0f 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -53,7 +53,7 @@ const appBaseQuery: BaseQueryFn<{ const result = await client({ url, method, data }); return { data: result.data, meta }; - } catch (error: unknown) { + } catch (error) { if (isAxiosError(error)) { return { error: { status: error.response?.status, data: error.response?.data }, diff --git a/src/services/apiClient.ts b/src/services/apiClient.ts index b8fa2b4c37..bf8ca835cf 100644 --- a/src/services/apiClient.ts +++ b/src/services/apiClient.ts @@ -74,7 +74,7 @@ export async function getLinkedApiClient(): Promise { export async function maybeGetLinkedApiClient(): Promise { try { return await getLinkedApiClient(); - } catch (error: unknown) { + } catch (error) { if (error instanceof ExtensionNotLinkedError) { return null; } diff --git a/src/services/locator.ts b/src/services/locator.ts index 510e3fd556..957e83602a 100644 --- a/src/services/locator.ts +++ b/src/services/locator.ts @@ -133,7 +133,7 @@ class LazyLocatorFactory { { requireLinked: true } ); console.debug(`Fetched ${this.remote.length} remote service auths`); - } catch (error: unknown) { + } catch (error) { if (error instanceof ExtensionNotLinkedError) { this.remote = []; } else { diff --git a/src/services/useDependency.ts b/src/services/useDependency.ts index 9eda937ae9..6a705872b2 100644 --- a/src/services/useDependency.ts +++ b/src/services/useDependency.ts @@ -118,7 +118,7 @@ function useDependency(serviceId: RegistryId | RegistryId[]): Dependency { } else if (!result) { notify.warning("You must accept the permissions request"); } - } catch (error: unknown) { + } catch (error) { setGrantedPermissions(false); notify.error(`Error granting permissions: ${getErrorMessage(error)}`, { error, diff --git a/src/telemetry/events.ts b/src/telemetry/events.ts index cc044bfe3e..a7cea59423 100644 --- a/src/telemetry/events.ts +++ b/src/telemetry/events.ts @@ -24,13 +24,13 @@ import { JsonObject } from "type-fest"; */ export function reportEvent(event: string, data: JsonObject = {}): void { console.debug(event, data); - void recordEvent({ event, data }).catch((error: unknown) => { + void recordEvent({ event, data }).catch((error) => { console.warn("Error reporting event %s", event, { error }); }); } export function initTelemetry(): void { - void initUID().catch((error: unknown) => { + void initUID().catch((error) => { console.warn("Error initializing uid", { error }); }); } diff --git a/src/telemetry/logging.ts b/src/telemetry/logging.ts index 22a5a073b0..80c8b53a3d 100644 --- a/src/telemetry/logging.ts +++ b/src/telemetry/logging.ts @@ -28,7 +28,7 @@ import { selectError } from "@/errors"; * @param context optional context for error telemetry */ export function reportError(error: unknown, context?: MessageContext): void { - void _reportError(error, context).catch((reportingError: unknown) => { + void _reportError(error, context).catch((reportingError) => { console.error("An error occurred when reporting an error", { originalError: error, reportingError, diff --git a/src/telemetry/rollbar.ts b/src/telemetry/rollbar.ts index 915b6f6409..33f38cb739 100644 --- a/src/telemetry/rollbar.ts +++ b/src/telemetry/rollbar.ts @@ -77,7 +77,7 @@ export const rollbar: Rollbar = (() => { } }, }); - } catch (error: unknown) { + } catch (error) { console.error("Error during rollbar init", { error }); } })(); diff --git a/src/utils.ts b/src/utils.ts index fca05d384e..5b2d84122f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -333,7 +333,7 @@ export async function rejectOnCancelled( let rv: T; try { rv = await promise; - } catch (error: unknown) { + } catch (error) { if (isCancelled()) { throw new PromiseCancelled("Promise was cancelled"); } diff --git a/src/validators/generic.ts b/src/validators/generic.ts index accc968ea5..90ad5e6121 100644 --- a/src/validators/generic.ts +++ b/src/validators/generic.ts @@ -187,7 +187,7 @@ async function validateExtension( let validated = true; try { await extensionValidator.validate(extension); - } catch (error: unknown) { + } catch (error) { validated = false; schemaErrors = error; } @@ -200,7 +200,7 @@ async function validateExtension( console.debug(`Validating ${extension.id} service ${service.id}`); try { await locate(service.id, service.config); - } catch (error: unknown) { + } catch (error) { if (error instanceof MissingConfigurationError) { missingConfiguration.push(error); } else if (error instanceof NotConfiguredError) { diff --git a/src/validators/validation.ts b/src/validators/validation.ts index bde5506e08..b0f93de147 100644 --- a/src/validators/validation.ts +++ b/src/validators/validation.ts @@ -163,7 +163,7 @@ function serviceSchemaFactory(): Yup.Schema { async (value) => { try { await serviceRegistry.lookup(validateRegistryId(value)); - } catch (error: unknown) { + } catch (error) { if (error instanceof DoesNotExistError) { return false; } @@ -206,7 +206,7 @@ function serviceSchemaFactory(): Yup.Schema { try { await locate(this.parent.id, value); - } catch (error: unknown) { + } catch (error) { if (error instanceof MissingConfigurationError) { return this.createError({ message: "Configuration no longer available", diff --git a/tsconfig.json b/tsconfig.json index b5e5725c94..c59229d402 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,6 @@ "resolveJsonModule": true, "baseUrl": ".", "skipLibCheck": false, - "useUnknownInCatchVariables": true, // TODO: Drop these lines to make TS stricter https://github.com/pixiebrix/pixiebrix-extension/issues/775 "strictNullChecks": false,