twilight-rs / twilight

Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.
https://discord.gg/twilight-rs
ISC License
656 stars 130 forks source link

Error message is unhelpful, and this doesn't require an error #2306

Closed SpellignErr closed 5 months ago

SpellignErr commented 8 months ago

https://github.com/twilight-rs/twilight/blob/29d213393b863aff6e013822299baff91539e643/twilight-validate/src/command.rs#L328

When creating a new command of CommandType::Message or CommandType::User a description is not allowed. If attempting to create a command of either of these types with a description, Twilight will throw an error: Error: command description must be between 1 and 100 characters. This error is of course incorrect.

This brings about a design choice: Should the crate err at all under these circumstances? Or is it an acceptable choice to simply replace the description with a blank string, and send a warning.

Example code:

CommandBuilder::new("Foobar", "This will cause error", CommandType::User)
        .guild_id(Id::new(123))
        .nsfw(false)
        .validate()?
        .build();

Error:

Error: command description must be between 1 and 100 characters // Author's note: This is incorrect, the description must be exactly 0 characters (a blank string)

Traceback is available upon request or at https://discord.com/channels/745809834183753828/1193659646112698418/1193659836584448051

Erk- commented 5 months ago

I have resolved the part of the misleading error message in #2329.

I am not sure it is a good idea to silently fix the issue by for example just emptying the string when it is a Message or User command since it can lead to expectation that something should work, but it is stripped off before it is sent.