#[non_exhaustive]pub enum ValidationError {
TooLong {
field: Cow<'static, str>,
max: usize,
actual: usize,
},
TooMany {
field: Cow<'static, str>,
max: usize,
actual: usize,
},
TooFew {
field: Cow<'static, str>,
min: usize,
actual: usize,
},
Missing {
field: Cow<'static, str>,
},
OutOfRange {
field: Cow<'static, str>,
min: i64,
max: i64,
actual: i64,
},
InvalidUrl {
field: Cow<'static, str>,
allowed: &'static [&'static str],
},
InvalidName {
field: Cow<'static, str>,
character: char,
},
Invalid {
field: Cow<'static, str>,
reason: &'static str,
},
Empty {
field: Cow<'static, str>,
needs: &'static str,
},
}Expand description
A Discord limit or rule broken by a builder’s content, returned by build() (D-179).
build() stops at the first violation it finds and returns it (D-182). field is the
path of the offending value in the JSON sent to Discord, written the way Discord writes it
in its own 50035 Invalid Form Body errors — title, fields[3].name, author.url — so
both kinds of error point at the same place.
Texts are measured like Discord measures them: in Unicode code points
(str::chars), without leading and trailing whitespace (D-183, confirmed on the live
API). An emoji such as 🔥 counts once — discord.js would count it twice.
discord.js counterpart: the errors thrown by the setters of @discordjs/builders
(ValidationError / CombinedError from @sapphire/shapeshift).
§Examples
use djs_builders::{EmbedBuilder, ValidationError};
let error = EmbedBuilder::new().title("x".repeat(300)).build().unwrap_err();
assert_eq!(
error,
ValidationError::TooLong { field: "title".into(), max: 256, actual: 300 }
);
assert_eq!(error.field(), "title");
assert_eq!(error.to_string(), "title is too long: 300 characters, at most 256 allowed");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
TooLong
A text is longer than Discord allows.
Fields
TooMany
A list has more items than Discord allows.
Fields
TooFew
A list has fewer items than Discord requires — for example an empty action row.
Fields
Missing
A value that Discord requires is not set.
OutOfRange
A number is outside the range Discord allows.
Fields
InvalidUrl
A URL does not start with one of the schemes Discord allows for it (D-187, D-190).
Only the scheme is checked; Discord itself rejects a malformed address such as a bare
https://.
Fields
InvalidName
A command, subcommand or option name has a character Discord does not allow (D-194):
anything but letters, numbers, -, _ and ʼ, or a letter that has a lower-case
form.
Fields
Invalid
Values that are valid one by one do not work together — for example a required option
after an optional one, or choices together with autocomplete.
Fields
Empty
A value has no content at all, which Discord rejects — for example an embed with nothing but a color.
Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub fn field(&self) -> &str
pub fn field(&self) -> &str
Returns the path of the value that breaks the rule, e.g. fields[3].name.
discord.js counterpart: none (the path inside a validation error of @sapphire/shapeshift).
§Examples
use djs_builders::EmbedBuilder;
let error = EmbedBuilder::new().field("ok", "y".repeat(2000)).build().unwrap_err();
assert_eq!(error.field(), "fields[0].value");Trait Implementations§
Source§impl Clone for ValidationError
impl Clone for ValidationError
Source§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
impl Eq for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl Hash for ValidationError
impl Hash for ValidationError
Source§impl PartialEq for ValidationError
impl PartialEq for ValidationError
impl StructuralPartialEq for ValidationError
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin for ValidationError
impl UnsafeUnpin for ValidationError
impl UnwindSafe for ValidationError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more