Skip to content

Commit

Permalink
fix(listeners): ignore UserError (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Nov 2, 2024
1 parent adbf5cd commit 473ccf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/listeners/errors/listenerError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Events, Listener, type ListenerErrorPayload } from '@sapphire/framework';
import { Events, Listener, UserError, type ListenerErrorPayload } from '@sapphire/framework';

export class UserListener extends Listener<typeof Events.ListenerError> {
public run(error: Error, context: ListenerErrorPayload) {
// We generally do not care about `UserError`s in listeners since they're not bugs.
if (error instanceof UserError) return;

this.container.logger.fatal(`[EVENT] ${context.piece.name}\n${error.stack || error.message}`);
}
}
5 changes: 4 additions & 1 deletion src/listeners/errors/listenerErrorSentry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ApplyOptions } from '@sapphire/decorators';
import { Events, Listener, type ListenerErrorPayload } from '@sapphire/framework';
import { Events, Listener, UserError, type ListenerErrorPayload } from '@sapphire/framework';
import { captureException } from '@sentry/node';
import { envIsDefined } from '@skyra/env-utilities';

@ApplyOptions({ enabled: envIsDefined('SENTRY_URL') })
export class UserListener extends Listener<typeof Events.ListenerError> {
public run(error: Error, context: ListenerErrorPayload) {
// We generally do not care about `UserError`s in listeners since they're not bugs.
if (error instanceof UserError) return;

captureException(error, { tags: { name: context.piece.name } });
}
}

0 comments on commit 473ccf5

Please sign in to comment.