fix(lib/modules/finders): don't let one bad filter take down the whole process
This commit is contained in:
parent
9a10e9d509
commit
c096b80225
1 changed files with 23 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { getErrorStack } from '@revenge-mod/utils/error'
|
||||
import { withProps } from '.'
|
||||
import { and, or } from './composite'
|
||||
import { FilterScopes } from './constants'
|
||||
|
|
@ -203,8 +204,17 @@ export function createFilterGenerator<A extends any[]>(
|
|||
const isDefaultScopesStatic = typeof defaultScopes === 'number'
|
||||
|
||||
const generator: GeneratorType = (...args: A) => {
|
||||
const filter_ = ((id: Metro.ModuleID, exports?: Metro.ModuleExports) =>
|
||||
filter(args, id, exports)) as ReturnType<GeneratorType>
|
||||
const filter_ = ((
|
||||
id: Metro.ModuleID,
|
||||
exports?: Metro.ModuleExports,
|
||||
) => {
|
||||
try {
|
||||
return filter(args, id, exports)
|
||||
} catch (e) {
|
||||
DEBUG_warnFilterThrown(id, keyFor(args), e)
|
||||
return false
|
||||
}
|
||||
}) as ReturnType<GeneratorType>
|
||||
|
||||
filter_.key = keyFor(args)
|
||||
filter_.flags = isFlagsStatic ? flagFor : flagFor(args)
|
||||
|
|
@ -226,3 +236,14 @@ export function createFilterGenerator<A extends any[]>(
|
|||
|
||||
return generator
|
||||
}
|
||||
|
||||
function DEBUG_warnFilterThrown(
|
||||
id: Metro.ModuleID,
|
||||
key: string,
|
||||
error: unknown,
|
||||
) {
|
||||
nativeLoggingHook(
|
||||
`\u001b[31mFilter ${key} threw an error for module ${id}:\n${getErrorStack(error)}\u001b[0m`,
|
||||
3,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue