pub struct Error {
pub code: ErrorCode,
pub message: String,
pub subject: Option<Subject>,
pub correlation_id: Option<CorrelationId>,
pub causation_id: Option<CausationId>,
pub details: Option<Value>,
}Expand description
The canonical error type. Transport adapters project this into GraphQL errors, MQTT error topics, SSE error frames, etc. Transport adapters must not define their own error types.
Fields§
§code: ErrorCodeCanonical error code.
message: StringHuman-readable error message.
subject: Option<Subject>Subject the error relates to.
correlation_id: Option<CorrelationId>Correlation id.
causation_id: Option<CausationId>Causation id.
details: Option<Value>Optional structured details.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Construct an error with a code and message.
Sourcepub fn transport_error(msg: impl Into<String>) -> Self
pub fn transport_error(msg: impl Into<String>) -> Self
Construct a transport error.
Sourcepub fn resolver_error(msg: impl Into<String>) -> Self
pub fn resolver_error(msg: impl Into<String>) -> Self
Construct a resolver error.
Sourcepub fn cache_miss(msg: impl Into<String>) -> Self
pub fn cache_miss(msg: impl Into<String>) -> Self
Construct a cache-miss error.
Sourcepub fn not_found(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
Construct a not-found error.
Use this when the authoritative store positively holds no such
entity, which is a different fact from a Self::cache_miss.
Sourcepub fn validation_error(msg: impl Into<String>) -> Self
pub fn validation_error(msg: impl Into<String>) -> Self
Construct a validation error.
Construct an authorization error.
This is a policy denial, not a resolver failure. Callers that fail closed on denial must match on it rather than treating it as a miss and retrying against the authority.
Sourcepub fn conflict(msg: impl Into<String>) -> Self
pub fn conflict(msg: impl Into<String>) -> Self
Construct a conflict error.
Signals a lost compare-and-set race. The input was well-formed; it was merely stale, so the caller may re-read and retry.
Sourcepub fn internal_error(msg: impl Into<String>) -> Self
pub fn internal_error(msg: impl Into<String>) -> Self
Construct an internal error.
Sourcepub fn with_subject(self, s: Subject) -> Self
pub fn with_subject(self, s: Subject) -> Self
Set the subject.
Sourcepub fn with_correlation(self, id: CorrelationId) -> Self
pub fn with_correlation(self, id: CorrelationId) -> Self
Set the correlation id.
Sourcepub fn with_causation(self, id: CausationId) -> Self
pub fn with_causation(self, id: CausationId) -> Self
Set the causation id.
Sourcepub fn with_details(self, details: Value) -> Self
pub fn with_details(self, details: Value) -> Self
Set structured details.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Error for Error
impl Error for Error
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()