ConfigError

Struct ConfigError 

Source
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

Source

pub fn pretty_print(&self, mode: ErrorPrintMode) -> String

Formats configuration errors in a human-readable format.

This method provides two formatting modes via ErrorPrintMode:

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

Source§

fn clone(&self) -> ConfigError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConfigError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ConfigError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.