From d515342526f406a15c081653657a44205be0ae52 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 16 Nov 2023 04:18:41 -0800 Subject: [PATCH] Add FlipperServerDisconnectedError to prevent excessive error logging Reviewed By: passy Differential Revision: D51393196 fbshipit-source-id: f49857b397a3fb629ad44f89a4c59b12ba2f67c4 --- desktop/flipper-common/src/index.tsx | 1 + desktop/flipper-common/src/utils/errors.tsx | 6 ++++++ desktop/flipper-frontend-core/src/plugins.tsx | 11 ++++++++++- .../flipper-server-client/src/FlipperServerClient.tsx | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/desktop/flipper-common/src/index.tsx b/desktop/flipper-common/src/index.tsx index 7925006b6..b89847fee 100644 --- a/desktop/flipper-common/src/index.tsx +++ b/desktop/flipper-common/src/index.tsx @@ -54,6 +54,7 @@ export { isConnectivityOrAuthError, isError, isAuthError, + FlipperServerDisconnectedError, getStringFromErrorLike, getErrorFromErrorLike, deserializeRemoteError, diff --git a/desktop/flipper-common/src/utils/errors.tsx b/desktop/flipper-common/src/utils/errors.tsx index 781c24113..76b1a1a6b 100644 --- a/desktop/flipper-common/src/utils/errors.tsx +++ b/desktop/flipper-common/src/utils/errors.tsx @@ -96,6 +96,12 @@ export class NoLongerConnectedToClientError extends Error { name: 'NoLongerConnectedToClientError'; } +export class FlipperServerDisconnectedError extends Error { + constructor(public readonly reason: 'ws-close') { + super(`Flipper Server disconnected. Reason: ${reason}`); + } +} + declare global { interface Error { interaction?: unknown; diff --git a/desktop/flipper-frontend-core/src/plugins.tsx b/desktop/flipper-frontend-core/src/plugins.tsx index 2375080b7..bd5573a2b 100644 --- a/desktop/flipper-frontend-core/src/plugins.tsx +++ b/desktop/flipper-frontend-core/src/plugins.tsx @@ -11,6 +11,7 @@ import { InstalledPluginDetails, tryCatchReportPluginFailuresAsync, notNull, + FlipperServerDisconnectedError, } from 'flipper-common'; import {ActivatablePluginDetails, ConcretePluginDetails} from 'flipper-common'; import {reportUsage} from 'flipper-common'; @@ -229,7 +230,15 @@ export const createRequirePluginFunction = return pluginDefinition; } catch (e) { failedPlugins.push([pluginDetails, e.message]); - console.error(`Plugin ${pluginDetails.id} failed to load`, e); + + let severity: 'error' | 'warn' = 'error'; + if ( + e instanceof FlipperServerDisconnectedError && + e.reason === 'ws-close' + ) { + severity = 'warn'; + } + console[severity](`Plugin ${pluginDetails.id} failed to load`, e); return null; } }; diff --git a/desktop/flipper-server-client/src/FlipperServerClient.tsx b/desktop/flipper-server-client/src/FlipperServerClient.tsx index 29985f65e..2f0b7323b 100644 --- a/desktop/flipper-server-client/src/FlipperServerClient.tsx +++ b/desktop/flipper-server-client/src/FlipperServerClient.tsx @@ -14,6 +14,7 @@ import { FlipperServerCommands, FlipperServerExecOptions, ServerWebSocketMessage, + FlipperServerDisconnectedError, } from 'flipper-common'; import ReconnectingWebSocket from 'reconnecting-websocket'; @@ -90,7 +91,7 @@ export function createFlipperServerWithSocket( onStateChange(FlipperServerState.DISCONNECTED); pendingRequests.forEach((r) => - r.reject(new Error('flipper-server disconnected')), + r.reject(new FlipperServerDisconnectedError('ws-close')), ); pendingRequests.clear(); });