pub struct ErrorPanel {
pub code: String,
pub title: String,
pub message: Option<String>,
pub severity: ErrorSeverity,
pub context: Vec<ErrorContext>,
pub suggestions: Vec<String>,
pub caused_by: Vec<CausedBy>,
pub stack_trace: Option<String>,
pub timestamp: DateTime<Utc>,
pub truncated: bool,
}Expand description
ErrorPanel - The base error display component for RCH.
Provides consistent, actionable error messages with:
- Error code and title
- Main message
- Context key-value pairs
- Remediation suggestions
- Error chaining support
- Timestamp for debugging
Fields§
§code: StringError code in RCH-Exxx format.
title: StringShort error title (e.g., “Worker Connection Failed”).
message: Option<String>Main error message with details.
severity: ErrorSeverityError severity level.
context: Vec<ErrorContext>Context key-value pairs (e.g., Host, Timeout).
suggestions: Vec<String>Remediation suggestions (numbered list).
caused_by: Vec<CausedBy>Error chain (caused by).
stack_trace: Option<String>Stack trace (usually collapsed/hidden).
timestamp: DateTime<Utc>Timestamp when the error occurred.
truncated: boolWhether the message was truncated (show –verbose hint).
Implementations§
Source§impl ErrorPanel
impl ErrorPanel
Sourcepub fn new(code: impl Into<String>, title: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, title: impl Into<String>) -> Self
Create a new ErrorPanel with code and title.
§Arguments
code- Error code (e.g., “RCH-E042”)title- Short error title (e.g., “Worker Connection Failed”)
Sourcepub fn error(code: impl Into<String>, title: impl Into<String>) -> Self
pub fn error(code: impl Into<String>, title: impl Into<String>) -> Self
Create an error-level ErrorPanel (red, cross icon).
Sourcepub fn warning(code: impl Into<String>, title: impl Into<String>) -> Self
pub fn warning(code: impl Into<String>, title: impl Into<String>) -> Self
Create a warning-level ErrorPanel (amber, warning icon).
Sourcepub fn info(code: impl Into<String>, title: impl Into<String>) -> Self
pub fn info(code: impl Into<String>, title: impl Into<String>) -> Self
Create an info-level ErrorPanel (blue, info icon).
Sourcepub fn with_severity(self, severity: ErrorSeverity) -> Self
pub fn with_severity(self, severity: ErrorSeverity) -> Self
Set the severity level.
Sourcepub fn message_truncated(
self,
message: impl Into<String>,
max_len: usize,
) -> Self
pub fn message_truncated( self, message: impl Into<String>, max_len: usize, ) -> Self
Set the main error message, truncating if too long.
If the message exceeds max_len characters, it will be truncated
and truncated will be set to true (shows –verbose hint).
Sourcepub fn context(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn context(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a context key-value pair.
Sourcepub fn suggestion(self, suggestion: impl Into<String>) -> Self
pub fn suggestion(self, suggestion: impl Into<String>) -> Self
Add a remediation suggestion.
Sourcepub fn suggestions<I, S>(self, suggestions: I) -> Self
pub fn suggestions<I, S>(self, suggestions: I) -> Self
Add multiple suggestions at once.
Sourcepub fn caused_by(self, message: impl Into<String>, code: Option<String>) -> Self
pub fn caused_by(self, message: impl Into<String>, code: Option<String>) -> Self
Add a caused-by error (for error chaining).
Sourcepub fn stack_trace(self, trace: impl Into<String>) -> Self
pub fn stack_trace(self, trace: impl Into<String>) -> Self
Add a stack trace (shown in verbose mode or dim).
Sourcepub fn with_timestamp(self, timestamp: DateTime<Utc>) -> Self
pub fn with_timestamp(self, timestamp: DateTime<Utc>) -> Self
Set the timestamp explicitly.
Sourcepub fn render(&self, ctx: OutputContext)
pub fn render(&self, ctx: OutputContext)
Render the error panel to stderr.
Automatically selects rich or plain output based on context.
Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
Serialize to JSON string.
Use this for –json mode output.
Sourcepub fn to_json_compact(&self) -> Result<String>
pub fn to_json_compact(&self) -> Result<String>
Serialize to compact JSON string.
Trait Implementations§
Source§impl Clone for ErrorPanel
impl Clone for ErrorPanel
Source§fn clone(&self) -> ErrorPanel
fn clone(&self) -> ErrorPanel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ErrorPanel
impl Debug for ErrorPanel
Source§impl<'de> Deserialize<'de> for ErrorPanel
impl<'de> Deserialize<'de> for ErrorPanel
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 Display for ErrorPanel
impl Display for ErrorPanel
Source§impl Error for ErrorPanel
impl Error for ErrorPanel
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()