fix: improved default error handler#1818
Open
mifuyutsuki wants to merge 8 commits into
Open
Conversation
- With the default error handler, ComponentError and ModalError now post errors, consistent with the handler for CommandError. - Added an error message post for BadArgument. - Migrated posted error messages to Components v2 to ensure the error message can be sent on Components v2 messages after defer(edit_origin=True), since a v1 message can be converted into v2 but not the other way around.
Added a message to the CommandCheckFailure class such that its __str__() is a proper error message rather than its repr.
In the default error handler, errors of the type CommandException e.g. CommandOnCooldown are now logged as info with its own log message instead of error. Logging as error would have emitted a traceback and a Sentry log.
Added check for ctx.editing_origin in default_error_send() to determine whether to use send() or edit_origin(). Set content and embeds fields to empty to ensure the function succeeds when the origin message is Components v1.
Added note that failed checks raise CommandCheckFailure and failed Converter conversions raise BadArgument.
Added point that Error by itself only logs errors, not post an error message, but that its subtypes CommandError (as well as ComponentError and ModalError) do.
silasary
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Description
The default error handler is now improved with several new fixes, as listed in the Changes section. Notably:
ComponentErrorandModalErrorcan now send default error messages, consistent withCommandError.BadArgumentis now handled with a message to the user.Changes
Client.default_error_send(), which handles sending of default error messages, called byComponentErrorandModalErrorin addition toCommandError.BadArgumentnow has its own default error message format, skipping the traceback.edit_origin=Trueregardless of using Components v2 or not. Components v2 messages cannot be edited into Components v1.CommandExceptione.g.CommandCheckFailurenow log as info instead of error, as they are known to be user errors than bot errors.CommandCheckFailure, showing the name of the failed check function instead of the current one, which is its repr().Related Issues
Test Scenarios
I've done at least the following:
@slash_command(), dispatchesCommandError@component_callback()with and withoutdefer(edit_origin=True), dispatchesComponentError@modal_callback()with and withoutdefer(edit_origin=True), dispatchesModalErrorCommandCheckFailureand posts "You don't have permission to run this command!"Python Compatibility
3.10.x3.11.xChecklist
pre-commitcode linter over all edited files