From b1cc67a860fe2b6546900797dfa49a936b97f7dd Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 8 May 2024 23:42:04 +0200 Subject: [PATCH 1/2] fix(BetterSettings): do not catch errors of other ui --- src/plugins/betterSettings/index.tsx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/plugins/betterSettings/index.tsx b/src/plugins/betterSettings/index.tsx index 7d81c6f5c..5836734ef 100644 --- a/src/plugins/betterSettings/index.tsx +++ b/src/plugins/betterSettings/index.tsx @@ -6,8 +6,8 @@ import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; -import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; +import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { ComponentDispatch, FocusLock, i18n, Menu, useEffect, useRef } from "@webpack/common"; @@ -124,12 +124,23 @@ export default definePlugin({ } ], + // This is the very outer layer of the entire ui, so we can't wrap this in an ErrorBoundary + // without possibly also catching unrelated errors of children. + // + // Thus, we sanity check webpack modules & do this really hacky try catch to hopefully prevent hard crashes if something goes wrong. + // try catch will only catch errors in the Layer function (hence why it's called as a plain function rather than a component), but + // not in children Layer(props: LayerProps) { - return ( - props.children as any}> - - - ); + try { + if (!FocusLock || !ComponentDispatch) + throw new Error("Failed to fetch some webpack modules"); + + return Layer(props); + } catch (e) { + new Logger("BetterSettings").error("Failed to render Layer", e); + } + + return props.children; }, wrapMenu(list: SettingsEntry[]) { From b7c1b495af5e25bd139738f520d25b464156b070 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 8 May 2024 18:37:27 -0300 Subject: [PATCH 2/2] CrashHandler: Increment timeout for trying to recover --- src/plugins/crashHandler/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/crashHandler/index.ts b/src/plugins/crashHandler/index.ts index f8c76d7f7..10053021f 100644 --- a/src/plugins/crashHandler/index.ts +++ b/src/plugins/crashHandler/index.ts @@ -104,7 +104,7 @@ export default definePlugin({ shouldAttemptRecover = false; // This is enough to avoid a crash loop - setTimeout(() => shouldAttemptRecover = true, 500); + setTimeout(() => shouldAttemptRecover = true, 1000); } catch { } try {