rch-common 1.0.26

Shared types and utilities for Remote Compilation Helper
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
//! ErrorPanel - Consistent, actionable error display for RCH.
//!
//! This module provides the base error display component with:
//! - Red-bordered panel with error icon and title
//! - Error code in header (RCH-Exxx format)
//! - Context section with relevant details
//! - Suggestion section with remediation steps
//! - Optional stack trace (collapsed by default)
//! - JSON serialization for machine output
//!
//! # Example
//!
//! ```ignore
//! use rch_common::ui::error::{ErrorPanel, ErrorSeverity};
//!
//! let error = ErrorPanel::new("RCH-E042", "Worker Connection Failed")
//!     .message("Could not establish SSH connection to worker 'build1'")
//!     .context("Host", "build1.internal (192.168.1.50:22)")
//!     .context("Timeout", "30s elapsed")
//!     .context("Last successful", "2h 15m ago")
//!     .suggestion("Check if worker is online: ssh build1.internal")
//!     .suggestion("Verify SSH key: ssh-add -l")
//!     .suggestion("Run: rch workers probe build1 --verbose");
//!
//! // Render to console
//! error.render(&console);
//!
//! // Or serialize to JSON
//! let json = serde_json::to_string(&error)?;
//! ```

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[cfg(all(feature = "rich-ui", unix))]
use rich_rust::r#box::HEAVY;
#[cfg(all(feature = "rich-ui", unix))]
use rich_rust::prelude::*;

use super::{Icons, OutputContext, RchTheme};

/// Error severity level.
///
/// Determines the color and icon used for display.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ErrorSeverity {
    /// Critical/error level - red border, cross icon.
    #[default]
    Error,
    /// Warning level - amber border, warning icon.
    Warning,
    /// Informational level - blue border, info icon.
    Info,
}

impl ErrorSeverity {
    /// Get the color hex code for this severity level.
    #[must_use]
    pub const fn color(&self) -> &'static str {
        match self {
            Self::Error => RchTheme::ERROR,
            Self::Warning => RchTheme::WARNING,
            Self::Info => RchTheme::INFO,
        }
    }

    /// Get the icon function for this severity level.
    #[must_use]
    pub fn icon(&self, ctx: OutputContext) -> &'static str {
        match self {
            Self::Error => Icons::cross(ctx),
            Self::Warning => Icons::warning(ctx),
            Self::Info => Icons::info(ctx),
        }
    }

    /// Get the severity name for display.
    #[must_use]
    pub const fn name(&self) -> &'static str {
        match self {
            Self::Error => "ERROR",
            Self::Warning => "WARN",
            Self::Info => "INFO",
        }
    }
}

impl std::fmt::Display for ErrorSeverity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}

/// A key-value context item for error details.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorContext {
    /// The context key (e.g., "Host", "Timeout").
    pub key: String,
    /// The context value (e.g., "build1.internal", "30s").
    pub value: String,
}

/// An error that caused this error (for error chaining).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CausedBy {
    /// Brief description of the cause.
    pub message: String,
    /// Optional error code of the cause.
    pub code: Option<String>,
}

/// 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
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorPanel {
    /// Error code in RCH-Exxx format.
    pub code: String,

    /// Short error title (e.g., "Worker Connection Failed").
    pub title: String,

    /// Main error message with details.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,

    /// Error severity level.
    pub severity: ErrorSeverity,

    /// Context key-value pairs (e.g., Host, Timeout).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub context: Vec<ErrorContext>,

    /// Remediation suggestions (numbered list).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub suggestions: Vec<String>,

    /// Error chain (caused by).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub caused_by: Vec<CausedBy>,

    /// Stack trace (usually collapsed/hidden).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stack_trace: Option<String>,

    /// Timestamp when the error occurred.
    pub timestamp: DateTime<Utc>,

    /// Whether the message was truncated (show --verbose hint).
    #[serde(default)]
    pub truncated: bool,
}

impl ErrorPanel {
    /// 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")
    #[must_use]
    pub fn new(code: impl Into<String>, title: impl Into<String>) -> Self {
        Self {
            code: code.into(),
            title: title.into(),
            message: None,
            severity: ErrorSeverity::Error,
            context: Vec::new(),
            suggestions: Vec::new(),
            caused_by: Vec::new(),
            stack_trace: None,
            timestamp: Utc::now(),
            truncated: false,
        }
    }

    /// Create an error-level ErrorPanel (red, cross icon).
    #[must_use]
    pub fn error(code: impl Into<String>, title: impl Into<String>) -> Self {
        Self::new(code, title).with_severity(ErrorSeverity::Error)
    }

    /// Create a warning-level ErrorPanel (amber, warning icon).
    #[must_use]
    pub fn warning(code: impl Into<String>, title: impl Into<String>) -> Self {
        Self::new(code, title).with_severity(ErrorSeverity::Warning)
    }

    /// Create an info-level ErrorPanel (blue, info icon).
    #[must_use]
    pub fn info(code: impl Into<String>, title: impl Into<String>) -> Self {
        Self::new(code, title).with_severity(ErrorSeverity::Info)
    }

    /// Set the severity level.
    #[must_use]
    pub fn with_severity(mut self, severity: ErrorSeverity) -> Self {
        self.severity = severity;
        self
    }

    /// Set the main error message.
    #[must_use]
    pub fn message(mut self, message: impl Into<String>) -> Self {
        self.message = Some(message.into());
        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).
    #[must_use]
    pub fn message_truncated(mut self, message: impl Into<String>, max_len: usize) -> Self {
        let msg = message.into();
        if msg.len() > max_len {
            self.message = Some(format!("{}...", &msg[..max_len.saturating_sub(3)]));
            self.truncated = true;
        } else {
            self.message = Some(msg);
        }
        self
    }

    /// Add a context key-value pair.
    #[must_use]
    pub fn context(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.context.push(ErrorContext {
            key: key.into(),
            value: value.into(),
        });
        self
    }

    /// Add a remediation suggestion.
    #[must_use]
    pub fn suggestion(mut self, suggestion: impl Into<String>) -> Self {
        self.suggestions.push(suggestion.into());
        self
    }

    /// Add multiple suggestions at once.
    #[must_use]
    pub fn suggestions<I, S>(mut self, suggestions: I) -> Self
    where
        I: IntoIterator<Item = S>,
        S: Into<String>,
    {
        self.suggestions
            .extend(suggestions.into_iter().map(Into::into));
        self
    }

    /// Add a caused-by error (for error chaining).
    #[must_use]
    pub fn caused_by(mut self, message: impl Into<String>, code: Option<String>) -> Self {
        self.caused_by.push(CausedBy {
            message: message.into(),
            code,
        });
        self
    }

    /// Add a stack trace (shown in verbose mode or dim).
    #[must_use]
    pub fn stack_trace(mut self, trace: impl Into<String>) -> Self {
        self.stack_trace = Some(trace.into());
        self
    }

    /// Set the timestamp explicitly.
    #[must_use]
    pub fn with_timestamp(mut self, timestamp: DateTime<Utc>) -> Self {
        self.timestamp = timestamp;
        self
    }

    // ========================================================================
    // RENDERING
    // ========================================================================

    /// Render the error panel to stderr.
    ///
    /// Automatically selects rich or plain output based on context.
    pub fn render(&self, ctx: OutputContext) {
        if ctx.is_machine() {
            // Machine mode - render nothing, caller should use to_json()
            return;
        }

        #[cfg(all(feature = "rich-ui", unix))]
        if ctx.supports_rich() {
            self.render_rich(ctx);
            return;
        }

        self.render_plain(ctx);
    }

    /// Render using rich_rust Panel.
    #[cfg(all(feature = "rich-ui", unix))]
    fn render_rich(&self, ctx: OutputContext) {
        let content = self.build_content(ctx, true);
        let icon = self.severity.icon(ctx);
        let title_text = format!("{icon} {}: {}", self.code, self.title);

        let border_color = Color::parse(self.severity.color()).unwrap_or_else(|_| Color::default());
        let border_style = Style::new().bold().color(border_color);

        let panel = Panel::from_text(&content)
            .title(title_text.as_str())
            .border_style(border_style)
            .box_style(&HEAVY);

        // Print to stderr via Console
        let console = Console::builder().force_terminal(true).build();
        console.print_renderable(&panel);
    }

    /// Render plain text to stderr.
    fn render_plain(&self, ctx: OutputContext) {
        let icon = self.severity.icon(ctx);
        let severity = self.severity.name();

        // Header line
        eprintln!("{icon} [{severity}] {}: {}", self.code, self.title);

        // Main message
        if let Some(ref msg) = self.message {
            eprintln!();
            eprintln!("{msg}");
        }

        // Context section
        if !self.context.is_empty() {
            eprintln!();
            eprintln!("Context:");
            for item in &self.context {
                eprintln!("  {}: {}", item.key, item.value);
            }
        }

        // Error chain
        if !self.caused_by.is_empty() {
            eprintln!();
            eprintln!("Caused by:");
            for cause in &self.caused_by {
                if let Some(ref code) = cause.code {
                    eprintln!("  [{code}] {}", cause.message);
                } else {
                    eprintln!("  {}", cause.message);
                }
            }
        }

        // Suggestions
        if !self.suggestions.is_empty() {
            eprintln!();
            eprintln!("Suggestions:");
            for (i, suggestion) in self.suggestions.iter().enumerate() {
                eprintln!("  {}. {suggestion}", i + 1);
            }
        }

        // Truncation hint
        if self.truncated {
            eprintln!();
            eprintln!("(Use --verbose for full message)");
        }

        // Stack trace (dim)
        if let Some(ref trace) = self.stack_trace {
            eprintln!();
            eprintln!("Stack trace:");
            for line in trace.lines() {
                eprintln!("  {line}");
            }
        }

        // Timestamp
        eprintln!();
        eprintln!("[{}]", self.timestamp.format("%Y-%m-%d %H:%M:%S UTC"));
    }

    /// Build content string for panel body.
    #[cfg(all(feature = "rich-ui", unix))]
    fn build_content(&self, ctx: OutputContext, _use_markup: bool) -> String {
        let mut lines = Vec::new();

        // Main message
        if let Some(ref msg) = self.message {
            lines.push(msg.clone());
        }

        // Context section
        if !self.context.is_empty() {
            lines.push(String::new());
            lines.push(format!("[{}]Context:[/]", RchTheme::DIM));
            for item in &self.context {
                lines.push(format!(
                    "  [{}]{}:[/] {}",
                    RchTheme::DIM,
                    item.key,
                    item.value
                ));
            }
        }

        // Error chain
        if !self.caused_by.is_empty() {
            lines.push(String::new());
            lines.push(format!("[{}]Caused by:[/]", RchTheme::DIM));
            for cause in &self.caused_by {
                if let Some(ref code) = cause.code {
                    lines.push(format!("  [{code}] {}", cause.message));
                } else {
                    lines.push(format!("  {}", cause.message));
                }
            }
        }

        // Suggestions
        if !self.suggestions.is_empty() {
            lines.push(String::new());
            lines.push(format!("[{}]Suggestions:[/]", RchTheme::SECONDARY));
            for (i, suggestion) in self.suggestions.iter().enumerate() {
                lines.push(format!(
                    "  [{}]{}.[/] {}",
                    RchTheme::SECONDARY,
                    i + 1,
                    suggestion
                ));
            }
        }

        // Truncation hint
        if self.truncated {
            lines.push(String::new());
            lines.push(format!(
                "[{}](Use --verbose for full message)[/]",
                RchTheme::DIM
            ));
        }

        // Stack trace (dim)
        if let Some(ref trace) = self.stack_trace {
            lines.push(String::new());
            lines.push(format!("[{}]Stack trace:[/]", RchTheme::DIM));
            for line in trace.lines() {
                lines.push(format!("[{}]  {line}[/]", RchTheme::DIM));
            }
        }

        // Timestamp
        lines.push(String::new());
        let timestamp_icon = Icons::clock(ctx);
        lines.push(format!(
            "[{}]{timestamp_icon} {}[/]",
            RchTheme::DIM,
            self.timestamp.format("%Y-%m-%d %H:%M:%S UTC")
        ));

        lines.join("\n")
    }

    /// Serialize to JSON string.
    ///
    /// Use this for --json mode output.
    pub fn to_json(&self) -> serde_json::Result<String> {
        serde_json::to_string_pretty(self)
    }

    /// Serialize to compact JSON string.
    pub fn to_json_compact(&self) -> serde_json::Result<String> {
        serde_json::to_string(self)
    }
}

impl std::fmt::Display for ErrorPanel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "[{}] {}: {}", self.severity, self.code, self.title)?;
        if let Some(ref msg) = self.message {
            write!(f, " - {msg}")?;
        }
        Ok(())
    }
}

impl std::error::Error for ErrorPanel {}

// ============================================================================
// CONVENIENCE FUNCTIONS
// ============================================================================

/// Create an error panel and render it immediately.
///
/// For quick error display without building the full panel manually.
pub fn show_error(code: &str, title: &str, message: &str, ctx: OutputContext) {
    ErrorPanel::error(code, title).message(message).render(ctx);
}

/// Create a warning panel and render it immediately.
pub fn show_warning(code: &str, title: &str, message: &str, ctx: OutputContext) {
    ErrorPanel::warning(code, title)
        .message(message)
        .render(ctx);
}

/// Create an info panel and render it immediately.
pub fn show_info(code: &str, title: &str, message: &str, ctx: OutputContext) {
    ErrorPanel::info(code, title).message(message).render(ctx);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_error_panel_creation() {
        let error = ErrorPanel::new("RCH-E042", "Test Error");
        assert_eq!(error.code, "RCH-E042");
        assert_eq!(error.title, "Test Error");
        assert_eq!(error.severity, ErrorSeverity::Error);
        assert!(error.message.is_none());
        assert!(error.context.is_empty());
        assert!(error.suggestions.is_empty());
    }

    #[test]
    fn test_error_panel_builder() {
        let error = ErrorPanel::error("RCH-E001", "Connection Failed")
            .message("Could not connect to worker")
            .context("Host", "192.168.1.10")
            .context("Port", "22")
            .suggestion("Check if worker is online")
            .suggestion("Verify SSH key");

        assert_eq!(error.severity, ErrorSeverity::Error);
        assert_eq!(
            error.message.as_deref(),
            Some("Could not connect to worker")
        );
        assert_eq!(error.context.len(), 2);
        assert_eq!(error.suggestions.len(), 2);
    }

    #[test]
    fn test_warning_panel() {
        let warning = ErrorPanel::warning("RCH-W001", "Slow Response");
        assert_eq!(warning.severity, ErrorSeverity::Warning);
    }

    #[test]
    fn test_info_panel() {
        let info = ErrorPanel::info("RCH-I001", "Build Complete");
        assert_eq!(info.severity, ErrorSeverity::Info);
    }

    #[test]
    fn test_message_truncation() {
        let long_message = "a".repeat(1000);
        let error = ErrorPanel::new("RCH-E001", "Test").message_truncated(long_message, 100);

        assert!(error.truncated);
        assert!(error.message.as_ref().unwrap().len() <= 100);
        assert!(error.message.as_ref().unwrap().ends_with("..."));
    }

    #[test]
    fn test_message_no_truncation_needed() {
        let short_message = "Short message";
        let error = ErrorPanel::new("RCH-E001", "Test").message_truncated(short_message, 100);

        assert!(!error.truncated);
        assert_eq!(error.message.as_deref(), Some("Short message"));
    }

    #[test]
    fn test_error_chaining() {
        let error = ErrorPanel::error("RCH-E042", "Connection Failed")
            .caused_by("SSH handshake failed", Some("SSH-001".to_string()))
            .caused_by("Network unreachable", None);

        assert_eq!(error.caused_by.len(), 2);
        assert_eq!(error.caused_by[0].code, Some("SSH-001".to_string()));
        assert!(error.caused_by[1].code.is_none());
    }

    #[test]
    fn test_json_serialization() {
        let error = ErrorPanel::error("RCH-E001", "Test Error")
            .message("Test message")
            .context("Key", "Value");

        let json = error.to_json().expect("JSON serialization failed");
        assert!(json.contains("RCH-E001"));
        assert!(json.contains("Test Error"));
        assert!(json.contains("Test message"));
    }

    #[test]
    fn test_json_compact_serialization() {
        let error = ErrorPanel::error("RCH-E001", "Test");
        let json = error.to_json_compact().expect("JSON serialization failed");
        // Compact JSON should not have newlines
        assert!(!json.contains('\n'));
    }

    #[test]
    fn test_display_implementation() {
        let error = ErrorPanel::error("RCH-E001", "Test Error").message("Details here");
        let display = format!("{error}");
        assert!(display.contains("ERROR"));
        assert!(display.contains("RCH-E001"));
        assert!(display.contains("Test Error"));
        assert!(display.contains("Details here"));
    }

    #[test]
    fn test_severity_colors() {
        assert_eq!(ErrorSeverity::Error.color(), RchTheme::ERROR);
        assert_eq!(ErrorSeverity::Warning.color(), RchTheme::WARNING);
        assert_eq!(ErrorSeverity::Info.color(), RchTheme::INFO);
    }

    #[test]
    fn test_severity_names() {
        assert_eq!(ErrorSeverity::Error.name(), "ERROR");
        assert_eq!(ErrorSeverity::Warning.name(), "WARN");
        assert_eq!(ErrorSeverity::Info.name(), "INFO");
    }

    #[test]
    fn test_severity_icons_plain() {
        let ctx = OutputContext::Plain;
        // Just verify they don't panic and return something
        assert!(!ErrorSeverity::Error.icon(ctx).is_empty());
        assert!(!ErrorSeverity::Warning.icon(ctx).is_empty());
        assert!(!ErrorSeverity::Info.icon(ctx).is_empty());
    }

    #[test]
    fn test_render_plain_mode() {
        let error = ErrorPanel::error("RCH-E001", "Test")
            .message("Message")
            .context("Key", "Value")
            .suggestion("Do something");

        // Should not panic
        error.render(OutputContext::Plain);
    }

    #[test]
    fn test_render_machine_mode_silent() {
        let error = ErrorPanel::error("RCH-E001", "Test");
        // Should not output anything in machine mode
        error.render(OutputContext::Machine);
    }

    #[test]
    fn test_render_hook_mode_silent() {
        let error = ErrorPanel::error("RCH-E001", "Test");
        // Should not output anything in hook mode
        error.render(OutputContext::Hook);
    }

    #[test]
    fn test_stack_trace() {
        let error =
            ErrorPanel::error("RCH-E001", "Test").stack_trace("at main.rs:42\nat lib.rs:100");

        assert!(error.stack_trace.is_some());
        assert!(error.stack_trace.as_ref().unwrap().contains("main.rs:42"));
    }

    #[test]
    fn test_multiple_suggestions() {
        let error = ErrorPanel::error("RCH-E001", "Test").suggestions([
            "First suggestion",
            "Second suggestion",
            "Third suggestion",
        ]);

        assert_eq!(error.suggestions.len(), 3);
    }

    #[test]
    fn test_default_severity() {
        let severity = ErrorSeverity::default();
        assert_eq!(severity, ErrorSeverity::Error);
    }

    #[test]
    fn test_convenience_functions_dont_panic() {
        // These should not panic even in Plain mode
        show_error("E001", "Test", "Message", OutputContext::Plain);
        show_warning("W001", "Test", "Message", OutputContext::Plain);
        show_info("I001", "Test", "Message", OutputContext::Plain);
    }

    #[test]
    fn test_error_panel_is_error_trait() {
        let error: Box<dyn std::error::Error> = Box::new(ErrorPanel::error("RCH-E001", "Test"));
        // Should be usable as a std::error::Error
        let _ = format!("{error}");
    }
}