mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 14:43:03 -04:00
WebpackPatcher: Try catch more code prone to errors
This commit is contained in:
parent
98b1b11dfa
commit
707d688887
2 changed files with 49 additions and 19 deletions
|
@ -60,7 +60,7 @@ export function getFactoryPatchedBy(moduleId: PropertyKey, webpackRequire = wreq
|
||||||
return webpackRequire.m[moduleId]?.[SYM_PATCHED_BY];
|
return webpackRequire.m[moduleId]?.[SYM_PATCHED_BY];
|
||||||
}
|
}
|
||||||
|
|
||||||
const logger = new Logger("WebpackInterceptor", "#8caaee");
|
const logger = new Logger("WebpackPatcher", "#8caaee");
|
||||||
|
|
||||||
/** Whether we tried to fallback to the WebpackRequire of the factory, or disabled patches */
|
/** Whether we tried to fallback to the WebpackRequire of the factory, or disabled patches */
|
||||||
let wreqFallbackApplied = false;
|
let wreqFallbackApplied = false;
|
||||||
|
@ -436,12 +436,21 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno
|
||||||
callback(exports, module.id);
|
callback(exports, module.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
"Error while filtering or firing callback for Webpack waitFor subscription:\n", err,
|
||||||
|
"\n\nModule exports:", exports,
|
||||||
|
"\n\nFilter:", filter,
|
||||||
|
"\n\nCallback:", callback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof exports !== "object") {
|
if (typeof exports !== "object") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const exportKey in exports) {
|
for (const exportKey in exports) {
|
||||||
|
try {
|
||||||
// Some exports might have not been initialized yet due to circular imports, so try catch it.
|
// Some exports might have not been initialized yet due to circular imports, so try catch it.
|
||||||
try {
|
try {
|
||||||
var exportValue = exports[exportKey];
|
var exportValue = exports[exportKey];
|
||||||
|
@ -454,9 +463,14 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno
|
||||||
callback(exportValue, module.id);
|
callback(exportValue, module.id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
"Error while filtering or firing callback for Webpack waitFor subscription:\n", err,
|
||||||
|
"\n\nExport value:", exports,
|
||||||
|
"\n\nFilter:", filter,
|
||||||
|
"\n\nCallback:", callback
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
logger.error("Error while firing callback for Webpack waitFor subscription:\n", err, filter, callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,17 @@ function makePropertyNonEnumerable(target: Record<PropertyKey, any>, key: Proper
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _blacklistBadModules(requireCache: NonNullable<AnyWebpackRequire["c"]>, exports: ModuleExports, moduleId: PropertyKey) {
|
export function _blacklistBadModules(requireCache: NonNullable<AnyWebpackRequire["c"]>, exports: ModuleExports, moduleId: PropertyKey) {
|
||||||
if (shouldIgnoreValue(exports)) {
|
try {
|
||||||
makePropertyNonEnumerable(requireCache, moduleId);
|
if (shouldIgnoreValue(exports)) {
|
||||||
return true;
|
makePropertyNonEnumerable(requireCache, moduleId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
"Error while blacklisting module:\n", err,
|
||||||
|
"\n\nModule id:", moduleId,
|
||||||
|
"\n\nModule exports:", exports,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof exports !== "object") {
|
if (typeof exports !== "object") {
|
||||||
|
@ -156,17 +164,25 @@ export function _blacklistBadModules(requireCache: NonNullable<AnyWebpackRequire
|
||||||
|
|
||||||
let hasOnlyBadProperties = true;
|
let hasOnlyBadProperties = true;
|
||||||
for (const exportKey in exports) {
|
for (const exportKey in exports) {
|
||||||
// Some exports might have not been initialized yet due to circular imports, so try catch it.
|
|
||||||
try {
|
try {
|
||||||
var exportValue = exports[exportKey];
|
// Some exports might have not been initialized yet due to circular imports, so try catch it.
|
||||||
} catch {
|
try {
|
||||||
continue;
|
var exportValue = exports[exportKey];
|
||||||
}
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldIgnoreValue(exportValue)) {
|
if (shouldIgnoreValue(exportValue)) {
|
||||||
makePropertyNonEnumerable(exports, exportKey);
|
makePropertyNonEnumerable(exports, exportKey);
|
||||||
} else {
|
} else {
|
||||||
hasOnlyBadProperties = false;
|
hasOnlyBadProperties = false;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
"Error while blacklistng module:\n", err,
|
||||||
|
"\n\nModule id:", moduleId,
|
||||||
|
"\n\nExport value:", exportValue,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue