PR: #51 (feat/23-testnet-config)
File: crates/charon-core/src/config.rs
Refs #51
Problem
Config::load() returns anyhow::Result<Self>. Every error — file-not-found, unset env var, TOML parse failure, and now the new validation failure (half-wired config) — surfaces as an untyped anyhow chain string.
This PR extends Config::load() to call a new validate() method. Validation errors expressed as anyhow strings cannot be matched by the CLI to give actionable recovery hints. An operator running the testnet profile for the first time gets:
Error: env var `CHARON_BNB_TESTNET_WS_URL` is not set
with no guidance on where to set it. A typed error would allow the CLI to add context ("Check .env or export the variable before starting").
Recurring thiserror convention: PRs #28, #39, #41, #44, #46 all flagged the same pattern on public lib APIs.
Fix
Define:
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ConfigError {
#[error("failed to read config file {path}: {source}")]
FileRead { path: PathBuf, #[source] source: std::io::Error },
#[error("env var `{var}` is not set (referenced in config at {path})")]
EnvVarMissing { var: String, path: PathBuf },
#[error("unterminated `${{" placeholder in config {path}")]
UnterminatedPlaceholder { path: PathBuf },
#[error("failed to parse TOML at {path}: {source}")]
TomlParse { path: PathBuf, #[source] source: toml::de::Error },
#[error("half-wired config: chain '{chain}' has {present} but not {missing}")]
HalfWired { chain: String, present: &'static str, missing: &'static str },
}
Change Config::load to Result<Self, ConfigError>. Add thiserror to charon-core/Cargo.toml and [workspace.dependencies].
PR: #51 (feat/23-testnet-config)
File: crates/charon-core/src/config.rs
Refs #51
Problem
Config::load()returnsanyhow::Result<Self>. Every error — file-not-found, unset env var, TOML parse failure, and now the new validation failure (half-wired config) — surfaces as an untyped anyhow chain string.This PR extends
Config::load()to call a newvalidate()method. Validation errors expressed as anyhow strings cannot be matched by the CLI to give actionable recovery hints. An operator running the testnet profile for the first time gets:with no guidance on where to set it. A typed error would allow the CLI to add context ("Check .env or export the variable before starting").
Recurring thiserror convention: PRs #28, #39, #41, #44, #46 all flagged the same pattern on public lib APIs.
Fix
Define:
Change
Config::loadtoResult<Self, ConfigError>. Addthiserrortocharon-core/Cargo.tomland[workspace.dependencies].