Skip to content

[PR #29] Config loader uses anyhow — public API needs ConfigError enum #80

@obchain

Description

@obchain

PR: #29 (feat/04-toml-config-loader)
File: crates/charon-core/src/config.rs, lines 79-91

Config::load returns anyhow::Result<Self>. Same rationale as issue #70 for trait: CLI + scanner + tests need to match on error variant (FileNotFound, UnsetEnvVar, ParseError, ValidationError) to decide exit code, retry, or user-friendly message.

Also pair with a Config::from_str(s: &str) -> Result<Self> constructor — current API takes path only, so unit tests must write a tempfile.

Fix:

#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
    #[error("config file not found: {0}")]
    NotFound(PathBuf),
    #[error("read error: {0}")]
    Io(#[source] std::io::Error),
    #[error("env var `{0}` not set")]
    UnsetEnvVar(String),
    #[error("unterminated ${{ in config")]
    UnterminatedInterp,
    #[error("TOML parse: {0}")]
    Parse(#[from] toml::de::Error),
    #[error("validation: {0}")]
    Validation(String),
}

impl Config {
    pub fn load(path: impl AsRef<Path>) -> Result<Self, ConfigError> { ... }
    pub fn from_str(s: &str) -> Result<Self, ConfigError> { ... }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polish

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions