baobao_codegen/adapters/error.rs
1//! Error handling adapter abstraction.
2//!
3//! This module defines the [`ErrorAdapter`] trait for abstracting error handling
4//! patterns (eyre, anyhow, thiserror, etc.).
5
6use super::cli::{Dependency, ImportSpec};
7
8/// Trait for error handling adapters.
9///
10/// Implement this trait to support a specific error handling library.
11pub trait ErrorAdapter {
12 /// Adapter name for identification.
13 fn name(&self) -> &'static str;
14
15 /// Dependencies required by this error adapter.
16 fn dependencies(&self) -> Vec<Dependency>;
17
18 /// The Result type alias or full type (e.g., "eyre::Result<()>").
19 fn result_type(&self, inner: &str) -> String;
20
21 /// The unit Result type (e.g., "eyre::Result<()>").
22 fn unit_result(&self) -> String {
23 self.result_type("()")
24 }
25
26 /// Imports needed for error handling.
27 fn imports(&self) -> Vec<ImportSpec>;
28
29 /// The error conversion expression (e.g., `.wrap_err("message")`).
30 fn wrap_error(&self, message: &str) -> Option<String>;
31}