[commands] Handle BadUnionArgument #3067
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!3067
Loading…
Reference in a new issue
No description provided.
Delete branch "laggron42/BadUnionArgument-handler"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
When using
typing.Unionfor a command argument, multiple conversion errors can happen and discord.py manages this by raisingcommands.BadUnionArgument. However, Red only handlescommands.BadArgument. ABadUnionArgumentwill currently display help.I added the support for this by creating a new class
MultipleConversionFailuresthat inherits fromBadUnionArgument, followingConversionFailure's logic. Message formatting is half-handled by discord.py (see here) and look like this:A bit of code was added on our side to also display each converter error. If only one message is available, then it will be displayed alone.
Example with two displayed messages:
Example with a single message:
I'm not sure I'm following the rationale behind adding another exception type instead of just handling the existing one we don't handle here.
Should just handle the bad union argument.
Additionally, we really shouldn't be sending exceptions to the user without confirming the exceptions are designed as user feedback here, this makes no attempt to see what the failures are, and just joins them to send.
Fixed. I didn't notice
BadUnionArgumentwas including all command errors instead of only catchingBadArguments. And I also removedMultipleConversionError, didn't realize the base class already included all needed arguments compared toConversionError.This is still presenting errors to users without any meangingful context.
Let's say for example the following converter
The user will then get two messages about the same arg telling them two converters failed.
This wont be user friendly, as the number of errors they are shown won't match the actual issue.
While it's true that each of the converters displaying an error did fail, it's not intuitive to an end user to see seperate failures to one argument without an explanation.
This may require a much more in depth handling of converters if we want to be able to retain this clarity while also supporting i18n
Currently, at least when users are sent help, the help text can be tailored to explain the usage of the command and have that be translated.
I haven't tested it but based on the previous review comments and my own expectations, I imagine that the general clarity of error messages will somewhat decrease if this were applied to Red on its own.
I think this may be an acceptable catch-all scenario but it would be great if we encouraged quality error messages by the usage of custom converters wherever possible.
I think we could provide a bunch of equivalent custom converters to commonly used
Unionconverters. It doesn't ensure that anyone uses them but it would make for a better experience.In addition to this, we could special-case on the Union's arguments (i.e. sth like `if converter == Union[discord.TextChannel, int]') to make sure that we don't lower the error messages in common scenarios. It shouldn't be hard to achieve and if we can convert a significant portion of error messages this way, I think it would be worth it.
Maybe we could even be a bit smarter about it than doing exact equality comparisons for the special cases but I think that this would be going into 'too much effort for not much gain' territory.
I'm not suggesting any concrete changes yet, just trying to revive discussion on this as, in general, the current UX of Union converter errors in Red leaves a lot to desire.
So, what do you think?
This PR was ported to the current codebase in
e75740cbbinstead of being merged as-is:Show the errors of all converters when a Union argument fails to convert,
instead of only showing the command's help.