pub enum GuardrailError {
StageFailed {
stage: String,
source: Box<dyn Error + Send + Sync>,
},
Config(String),
Upstream(String),
Serialization(Error),
Io(Error),
Regex(Error),
Internal(String),
}Expand description
Top-level error type used throughout guardrail-rs.
All errors are variants of this enum so that callers can handle them uniformly regardless of which crate or stage produced them.
Variants§
StageFailed
A pipeline stage failed during evaluation.
Fields
Config(String)
A configuration value was invalid or missing.
Upstream(String)
The upstream LLM request failed (reqwest-errors feature disabled).
Carries a pre-formatted message instead of the original error type,
avoiding a hard dependency on reqwest in minimal builds.
Serialization(Error)
JSON serialization or deserialization failed.
Io(Error)
An I/O error occurred.
Regex(Error)
A regex pattern failed to compile.
Internal(String)
An internal invariant was violated (should never happen in production).
Implementations§
Source§impl GuardrailError
impl GuardrailError
Sourcepub fn stage_failed(
stage: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn stage_failed( stage: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Self
Wrap any error as a StageFailed variant.
§Examples
use guardrail_core::GuardrailError;
let err = GuardrailError::stage_failed(
"my_stage",
std::io::Error::new(std::io::ErrorKind::Other, "disk full"),
);
assert!(err.to_string().contains("my_stage"));Sourcepub fn upstream(message: impl Into<String>) -> Self
pub fn upstream(message: impl Into<String>) -> Self
Construct an Upstream error from a message string.
Available regardless of the reqwest-errors feature, so call sites
that just want to report a string don’t need to feature-gate.
§Examples
use guardrail_core::GuardrailError;
let err = GuardrailError::upstream("connection refused");
assert!(err.to_string().contains("connection refused"));Trait Implementations§
Source§impl Debug for GuardrailError
impl Debug for GuardrailError
Source§impl Display for GuardrailError
impl Display for GuardrailError
Source§impl Error for GuardrailError
impl Error for GuardrailError
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()