fix: do not use emitter to emit error event

Discord's EventEmitter handles the `error` event specially for some reason.
This commit is contained in:
PalmDevs 2025-07-13 00:24:40 +07:00
parent 7bfb703e01
commit 37a20160db
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
3 changed files with 7 additions and 4 deletions

View file

@ -11,6 +11,9 @@ const [, _createClassModuleId] = lookupModule(byName('_createClass'))
const [, _classCallCheckModuleId] = lookupModule(byName('_classCallCheck'))
// ../discord_common/js/shared/utils/TypedEventEmitter.tsx
/**
* Do not use the `error` event, as the module will handle it specially for some reason.
*/
export let TypedEventEmitter: typeof DiscordModules.Utils.TypedEventEmitter =
proxify(() => {
const [module] = lookupModule(

View file

@ -30,7 +30,7 @@ export const pEmitter = new TypedEventEmitter<{
start: [InternalPlugin, PluginApi]
started: [InternalPlugin]
stopped: [InternalPlugin]
error: [InternalPlugin, unknown]
errored: [InternalPlugin, unknown]
}>()
export const pList = new Map<PluginManifest['id'], InternalPlugin>()
@ -88,7 +88,7 @@ function handlePluginError(e: unknown, plugin: InternalPlugin) {
2,
)
pEmitter.emit('error', plugin, e)
pEmitter.emit('errored', plugin, e)
if (!(iflags & InternalPluginFlags.Essential)) return plugin.disable()
}

View file

@ -21,7 +21,7 @@ export const RDTContext: {
const events = new TypedEventEmitter<{
connect: []
disconnect: []
error: [unknown]
errored: [unknown]
}>()
const CircleXIcon = lookupGeneratedIconComponent(
@ -47,7 +47,7 @@ export function connect() {
ws.addEventListener('error', e => {
cleanup()
events.emit('error', e)
events.emit('errored', e)
const err = (e as { message: string }).message ?? getErrorStack(e)
api.logger.error('React DevTools error:', err)