Enum CratestackError
#[non_exhaustive]pub enum CratestackError {
Show 16 variants
BadRequest(String),
NotAcceptable(String),
Unauthorized(String),
UnsupportedMediaType(String),
Forbidden(String),
NotFound(String),
Conflict(String),
ConflictTyped(DbErrorInfo),
Validation(String),
PreconditionFailed(String),
Codec(String),
Database(String),
DatabaseTyped(DbErrorInfo),
Internal(String),
Unavailable(String),
TooManyRequests(String),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
BadRequest(String)
4xx — String is the public message returned to the client.
NotAcceptable(String)
UnsupportedMediaType(String)
Forbidden(String)
NotFound(String)
Conflict(String)
ConflictTyped(DbErrorInfo)
Conflict (409) with structured database information preserved from
the driver — e.g. a unique-constraint violation. Prefer this over
Conflict(String) when the conflict originates from a database
error so CratestackError::db_sqlstate / CratestackError::db_constraint
keep working for callers that inspect the typed fields regardless of
whether the error surfaced as a 500 (DatabaseTyped) or a 409
(ConflictTyped).
Validation(String)
PreconditionFailed(String)
Codec(String)
5xx — String is operator-only detail. Never returned to clients;
the public message is a fixed canned string per variant.
Database(String)
Database error with only a stringified detail. Preserved for
back-compat; new code should prefer DatabaseTyped produced by
cratestack_sqlx::cratestack_error_from_sqlx.
DatabaseTyped(DbErrorInfo)
Database error with structured information preserved from the driver.
Use CratestackError::db_sqlstate and CratestackError::db_constraint to
access the typed fields without matching on this variant directly.
Internal(String)
503 — the operation cannot proceed right now, but a retry (from
scratch, not a resume) may succeed later. String is the
public, safe-to-expose message, mirroring the other 4xx-style
variants above.
Introduced for @@subscribe SSE backpressure overflow
(docs/design/rpc-transport.md §3.4/§3.4a: “bounded
per-subscription send buffer; on overflow, emit
Error{code:"unavailable"}”) — the first caller of the RPC
binding’s already-reserved "unavailable" code.
TooManyRequests(String)
429 — the caller exceeded a rate limit. String is the public,
safe-to-expose message, same treatment as the 4xx variants above.
Introduced for cratestack-axum’s RateLimitLayer (cratestack#846):
the throttled response used to be a hand-built text/plain 429 with
no error envelope at all, so a generated client decoded it as
“unrecognized error body” instead of a typed code. Expressing the
throttle as a CratestackError lets that response go through the
exact same encode path every other error in the stack takes, rather
than the layer inventing a second body shape.
Implementations§
§impl CratestackError
impl CratestackError
pub fn code(&self) -> &'static str
pub fn status_code(&self) -> StatusCode
pub fn public_message(&self) -> Cow<'_, str>
pub fn public_message(&self) -> Cow<'_, str>
Public, safe-to-expose message returned in HTTP responses.
For 4xx variants this is the caller-supplied string. For 5xx variants
this is a fixed canned message; the caller-supplied string flows to
detail instead and is recorded via tracing only.
pub fn detail(&self) -> Option<&str>
pub fn detail(&self) -> Option<&str>
Operator-only detail string. For 5xx variants this is the message
supplied at construction time; for 4xx variants this returns the same
string as public_message (callers are expected to pre-redact 4xx
messages they emit).
pub fn db_sqlstate(&self) -> Option<&str>
pub fn db_sqlstate(&self) -> Option<&str>
Returns the SQLSTATE code if this is a DatabaseTyped error with a
known code (e.g. "23505" for unique_violation).
Always returns None for the legacy Database(String) variant; to
get typed access, use cratestack_sqlx::cratestack_error_from_sqlx at the
conversion site.
pub fn db_constraint(&self) -> Option<&str>
pub fn db_constraint(&self) -> Option<&str>
Returns the constraint name if this is a DatabaseTyped error that
carries constraint information (e.g. "accounts_email_key").
Always returns None for the legacy Database(String) variant; to
get typed access, use cratestack_sqlx::cratestack_error_from_sqlx at the
conversion site.
pub fn into_response(self) -> CratestackErrorResponse
Trait Implementations§
§impl Debug for CratestackError
impl Debug for CratestackError
§impl Display for CratestackError
impl Display for CratestackError
§impl Error for CratestackError
impl Error for CratestackError
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()
Auto Trait Implementations§
impl Freeze for CratestackError
impl RefUnwindSafe for CratestackError
impl Send for CratestackError
impl Sync for CratestackError
impl Unpin for CratestackError
impl UnsafeUnpin for CratestackError
impl UnwindSafe for CratestackError
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§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();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§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();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§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();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§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();§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.
§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);