[Patcher] Error handling (skips patch if it errors)

pull/36/head
Oj18 3 years ago
parent 6ef943ac2f
commit 3d4cb0ffe3

@ -9,6 +9,9 @@
- Stopped authors with discriminators being separated with just author name
- Added newline support to loading toast
- ### Patcher API Improvements
- Added error handling if patches cause an error (it now just skips the patch instead of likely crashing)
- ### Fixes
- Made custom version info in settings more precise and should no longer crash if also using Powercord's BDCompat when opening settings
- Fixed crashes for modules using color picker component in settings without initial value

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

@ -12,11 +12,15 @@ const beforePatches = (context, args, id, functionName) => {
let newArgs;
for (const patch of patches) {
newArgs = patch.call(context, args);
try {
newArgs = patch.call(context, args);
if (newArgs === false) return false;
if (newArgs === false) return false;
if (!Array.isArray(newArgs)) newArgs = args;
if (!Array.isArray(newArgs)) newArgs = args;
} catch (e) {
console.error(`Before patch (${id} - ${functionName}) failed, skipping`);
}
}
return newArgs;
@ -28,7 +32,11 @@ const afterPatches = (context, newArgs, returnValue, id, functionName) => {
let newReturnValue = returnValue;
for (const patch of patches) {
newReturnValue = patch.call(context, newArgs, newReturnValue);
try {
newReturnValue = patch.call(context, newArgs, newReturnValue);
} catch (e) {
console.error(`After patch (${id} - ${functionName}) failed, skipping`);
}
}
return newReturnValue;

Loading…
Cancel
Save