fix(lib/modules/finders): don't let one bad filter take down the whole process

This commit is contained in:
PalmDevs 2026-08-02 16:54:30 +07:00
parent 9a10e9d509
commit c096b80225
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -1,3 +1,4 @@
import { getErrorStack } from '@revenge-mod/utils/error'
import { withProps } from '.' import { withProps } from '.'
import { and, or } from './composite' import { and, or } from './composite'
import { FilterScopes } from './constants' import { FilterScopes } from './constants'
@ -203,8 +204,17 @@ export function createFilterGenerator<A extends any[]>(
const isDefaultScopesStatic = typeof defaultScopes === 'number' const isDefaultScopesStatic = typeof defaultScopes === 'number'
const generator: GeneratorType = (...args: A) => { const generator: GeneratorType = (...args: A) => {
const filter_ = ((id: Metro.ModuleID, exports?: Metro.ModuleExports) => const filter_ = ((
filter(args, id, exports)) as ReturnType<GeneratorType> 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_.key = keyFor(args)
filter_.flags = isFlagsStatic ? flagFor : flagFor(args) filter_.flags = isFlagsStatic ? flagFor : flagFor(args)
@ -226,3 +236,14 @@ export function createFilterGenerator<A extends any[]>(
return generator 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,
)
}