pub struct ConfigError {
pub field_errors: Vec<ConfigFieldError>,
}Expand description
Error returned when configuration loading fails.
Contains a collection of all field-level errors encountered during the loading process. This allows you to see and handle all configuration problems at once rather than stopping at the first error.
§Examples
use tryphon::Config;
#[derive(Config)]
struct AppConfig {
#[env("DATABASE_URL")]
database_url: String,
#[env("PORT")]
port: u16,
}
match AppConfig::load() {
Ok(config) => {
// Use the configuration
}
Err(config_error) => {
eprintln!("Found {} configuration error(s):", config_error.field_errors.len());
for error in &config_error.field_errors {
eprintln!(" - {:?}", error);
}
}
}Fields§
§field_errors: Vec<ConfigFieldError>A vector of all field-level errors encountered during configuration loading.
Each error represents a problem with a specific field, such as a missing environment variable or a parsing failure.
Implementations§
Source§impl ConfigError
impl ConfigError
Sourcepub fn pretty_print(&self, mode: ErrorPrintMode) -> String
pub fn pretty_print(&self, mode: ErrorPrintMode) -> String
Formats configuration errors in a human-readable format.
This method provides two formatting modes via ErrorPrintMode:
ErrorPrintMode::List- Compact bulleted list format, ideal for log filesErrorPrintMode::Table- ASCII table format with columns, ideal for terminal output
Both formats include all error details including nested errors from nested configuration structs.
§Arguments
mode- The output format mode to use
§Returns
A formatted string containing all configuration errors with a header “Configuration errors:”
§Examples
§List Mode
use tryphon::{Config, ErrorPrintMode};
#[derive(Config)]
struct AppConfig {
#[env("MISSING_VAR")]
value: String,
}
match AppConfig::load() {
Ok(_) => println!("Config loaded"),
Err(e) => {
// Prints: Found 1 configuration error(s):
// Missing value for field 'value', tried env vars: MISSING_VAR
eprintln!("{}", e.pretty_print(ErrorPrintMode::List));
}
}§Table Mode
use tryphon::{Config, ErrorPrintMode};
#[derive(Config)]
struct AppConfig {
#[env("PORT")]
port: u16,
}
match AppConfig::load() {
Ok(_) => {},
Err(e) => {
// Prints a formatted ASCII table:
// ┌────────────┬────────────────────────┬─────────────────────────┐
// │ Field Name │ Environment Variables │ Error Details │
// ├────────────┼────────────────────────┼─────────────────────────┤
// │ port │ PORT │ invalid digit found... │
// └────────────┴────────────────────────┴─────────────────────────┘
eprintln!("{}", e.pretty_print(ErrorPrintMode::Table));
}
}Trait Implementations§
Source§impl Clone for ConfigError
impl Clone for ConfigError
Source§fn clone(&self) -> ConfigError
fn clone(&self) -> ConfigError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConfigError
impl Debug for ConfigError
Auto Trait Implementations§
impl Freeze for ConfigError
impl RefUnwindSafe for ConfigError
impl Send for ConfigError
impl Sync for ConfigError
impl Unpin for ConfigError
impl UnwindSafe for ConfigError
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
Mutably borrows from an owned value. Read more