pub struct Error<C: ErrorCode> {
pub code: C,
pub message: String,
pub hint: Option<String>,
pub context: Option<String>,
pub source: Option<Arc<dyn StdError + Send + Sync>>,
}Expand description
Generic error type that combines error codes with rich error context.
Fields§
§code: CError code for categorization and programmatic handling
message: StringUser-facing error message
hint: Option<String>Optional hint to help users resolve the issue
context: Option<String>Context for debugging
source: Option<Arc<dyn StdError + Send + Sync>>Source error chain for debugging
Implementations§
Source§impl<C: ErrorCode> Error<C>
impl<C: ErrorCode> Error<C>
Sourcepub fn new(code: C, message: impl Into<String>) -> Self
pub fn new(code: C, message: impl Into<String>) -> Self
Creates a new error with the given code and message.
Sourcepub fn with_hint(self, hint: impl Into<String>) -> Self
pub fn with_hint(self, hint: impl Into<String>) -> Self
Adds a hint to help users resolve the issue.
Hints should provide actionable guidance for end users.
Sourcepub fn with_context(self, context: impl Into<String>) -> Self
pub fn with_context(self, context: impl Into<String>) -> Self
Adds internal context for debugging.
Context is meant for developers and should include information about what the system was doing when the error occurred. TODO: currently unarmed, but can be used to log errors in a standardized way in the future.
Sourcepub fn with_source(self, source: impl StdError + Send + Sync + 'static) -> Self
pub fn with_source(self, source: impl StdError + Send + Sync + 'static) -> Self
Adds a source error for error chaining.
This is useful for preserving the original error that caused this error.
Sourcepub fn with_source_arc(self, source: Arc<dyn StdError + Send + Sync>) -> Self
pub fn with_source_arc(self, source: Arc<dyn StdError + Send + Sync>) -> Self
Adds a source error from an existing Arc.
This is useful when forwarding errors that are already wrapped in an Arc, avoiding unnecessary allocations.
Trait Implementations§
Source§impl<C: ErrorCode> Error for Error<C>
Implements the standard error trait for error chaining.
impl<C: ErrorCode> Error for Error<C>
Implements the standard error trait for error chaining.
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl<C: ErrorCode + ErrorStatusConversionExt> From<Error<C>> for Status
Converts a GreenlightError into a tonic::Status for gRPC transmission.
impl<C: ErrorCode + ErrorStatusConversionExt> From<Error<C>> for Status
Converts a GreenlightError into a tonic::Status for gRPC transmission.
The error details are JSON-encoded and included in the status details field. If JSON serialization fails, a fallback JSON string is used.
Source§impl<C: ErrorCode> TryFrom<Status> for Error<C>
Attempts to convert a tonic::Status back into a GreenlightError.
impl<C: ErrorCode> TryFrom<Status> for Error<C>
Attempts to convert a tonic::Status back into a GreenlightError.
This requires that:
- The status contains valid JSON details in the expected format
- The error code in the details can be mapped to a valid
Cvariant
Returns an anyhow::Error if parsing fails or the error code is unknown.
Auto Trait Implementations§
impl<C> !RefUnwindSafe for Error<C>
impl<C> !UnwindSafe for Error<C>
impl<C> Freeze for Error<C>where
C: Freeze,
impl<C> Send for Error<C>
impl<C> Sync for Error<C>
impl<C> Unpin for Error<C>where
C: Unpin,
impl<C> UnsafeUnpin for Error<C>where
C: UnsafeUnpin,
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,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request