pub enum WriteError {
Show 14 variants
RequiredFieldMissing {
field: String,
},
BlankNotAllowed {
field: String,
},
ForeignKeyNotFound {
field: String,
target_table: String,
value: Value,
},
UniqueViolation {
field: Option<String>,
value: Option<Value>,
},
NotNullViolation {
field: Option<String>,
},
CheckViolation {
constraint: Option<String>,
},
ForeignKeyViolation {
field: Option<String>,
},
Multiple {
errors: Vec<WriteError>,
},
TypeMismatch {
field: String,
expected: SqlType,
got: String,
},
Validator {
field: String,
message: String,
},
NotAnObject,
SerializeFailed(Error),
Sqlx(Error),
UnknownColumn {
field: String,
},
}Expand description
Errors that can surface when converting JSON values to bindable
sea-query values, when pre-validating against the schema, or
when the write itself fails. Every variant that the REST /
admin plugins surface as a per-field error has its own
structured shape so the boundary translation is a match, not
a string parse.
Variants§
RequiredFieldMissing
A non-nullable field received a JSON null (or was absent on
create). Names the offending field.
BlankNotAllowed
A non-nullable text field received an empty string where a
meaningful value was required (a non-blank text column).
Surfaced by pre-validation in insert_json.
ForeignKeyNotFound
A foreign-key column references a row that doesn’t exist in the target table. Pre-validated against the live DB before the INSERT/UPDATE so the response keys the error under the FK column with the offending value.
UniqueViolation
DB-side UNIQUE constraint failure. field is Some(col) when
the message / constraint name names the column (SQLite
always; Postgres via the <table>_<col>_key convention);
None for unparseable cases. value carries the offending
JSON value when the original body is still available.
NotNullViolation
DB-side NOT NULL constraint failure (caller bypassed pre- validation, e.g. via a raw transaction).
CheckViolation
DB-side CHECK constraint failure. Carries the constraint name when the engine surfaces it (Postgres does; SQLite gives just a generic message).
ForeignKeyViolation
DB-side foreign-key constraint failure that pre-validation missed (rare — typically a race where the target row was deleted between the existence check and the INSERT).
Multiple
Multiple validation errors at once. Surfaced by
insert_json when required + FK checks both fire, so the
caller can render every problem in one response.
Fields
errors: Vec<WriteError>TypeMismatch
The JSON value couldn’t be coerced to the column’s SqlType. e.g. a string body where an integer was expected.
Validator
Format validator (#[umbral(slug)] / email / url /
min = N / max = N) rejected the value.
NotAnObject
serde_json couldn’t serialize the instance to a JSON
object (the only shape Manager::create accepts).
SerializeFailed(Error)
The model isn’t Serialize. Surfaced by the trait bound on
Manager::create; not actually constructable from runtime.
Kept here for completeness so the variant exists in the docs.
Sqlx(Error)
sqlx error during the write. Wraps the driver-level cause.
UnknownColumn
update_values received a column name that doesn’t exist on
the model. Caught early before SQL is built.
Implementations§
Source§impl WriteError
impl WriteError
Sourcepub fn field_errors(&self) -> BTreeMap<String, Vec<String>>
pub fn field_errors(&self) -> BTreeMap<String, Vec<String>>
Flatten into a {field: [messages, ...]} map.
Used by the REST plugin to render the 400 body; the admin
plugin will use the same shape for inline form errors.
Variants that aren’t tied to a specific field (raw sqlx,
NotAnObject, etc.) produce empty maps — the caller’s
non-field-error envelope covers those.
Sourcepub fn non_field_errors(&self) -> Vec<String>
pub fn non_field_errors(&self) -> Vec<String>
Non-field-level errors, for the non_field_errors
array. Only populated for the parseable-but-non-keyed
constraint variants and the multi-error wrapper.
Sourcepub fn code(&self) -> &'static str
pub fn code(&self) -> &'static str
Stable machine-readable code for the boundary layer. REST
puts this in the code field of the 400 body; admin uses
it to pick an inline error style.
Sourcepub fn is_validation(&self) -> bool
pub fn is_validation(&self) -> bool
true for the variants that represent user-fixable input
problems (renderable as a 400). false for genuine
infrastructure / serialization failures (which should
surface as 500s).
Trait Implementations§
Source§impl Debug for WriteError
impl Debug for WriteError
Source§impl Display for WriteError
impl Display for WriteError
Source§impl Error for WriteError
impl Error for WriteError
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 From<Error> for WriteError
impl From<Error> for WriteError
Source§impl From<Error> for WriteError
impl From<Error> for WriteError
Source§impl From<ValidationErrors> for WriteError
Lift the form-primitive ValidationErrors into the canonical
WriteError. Each per-field message becomes a
WriteError::Validator { field, message }; non-field messages
become an Anonymous validator carrying the bare message.
Wrapped under WriteError::Multiple when there’s more than one.
impl From<ValidationErrors> for WriteError
Lift the form-primitive ValidationErrors into the canonical
WriteError. Each per-field message becomes a
WriteError::Validator { field, message }; non-field messages
become an Anonymous validator carrying the bare message.
Wrapped under WriteError::Multiple when there’s more than one.
Source§fn from(e: ValidationErrors) -> Self
fn from(e: ValidationErrors) -> Self
Source§impl From<WriteError> for FormErrors
impl From<WriteError> for FormErrors
Source§fn from(e: WriteError) -> Self
fn from(e: WriteError) -> Self
Source§impl From<WriteError> for DynError
impl From<WriteError> for DynError
Source§fn from(e: WriteError) -> Self
fn from(e: WriteError) -> Self
Source§impl From<WriteError> for SaveError
impl From<WriteError> for SaveError
Source§fn from(e: WriteError) -> Self
fn from(e: WriteError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for WriteError
impl !UnwindSafe for WriteError
impl Freeze for WriteError
impl Send for WriteError
impl Sync for WriteError
impl Unpin for WriteError
impl UnsafeUnpin for WriteError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);