astrid-runtime/astrid · error
failed to format config: {e}
Error message
failed to format config: {e} What it means
Wraps an error from `resolved.show(show_format, section)` — the resolved configuration could not be rendered in the requested format (JSON or TOML). The CLI re-throws it with a uniform prefix so `astrid config show` failures are identifiable. It indicates the config data is present but cannot be serialized/formatted for display.
Source
Thrown at crates/astrid-cli/src/commands/config.rs:21
use anyhow::Result;
use astrid_config::{Config, ResolvedConfig, ShowFormat};
/// Show the resolved configuration with source annotations.
pub(crate) fn show_config(format: &str, section: Option<&str>) -> Result<()> {
let workspace_root = std::env::current_dir().ok();
let resolved = Config::load_with_layout(
workspace_root.as_deref(),
crate::workspace_layout::current(),
)?;
let show_format = match format {
"json" => ShowFormat::Json,
_ => ShowFormat::Toml,
};
let output = resolved
.show(show_format, section)
.map_err(|e| anyhow::anyhow!("failed to format config: {e}"))?;
println!("{output}");
Ok(())
}
/// Validate the current configuration.
#[expect(clippy::unnecessary_wraps)]
pub(crate) fn validate_config() -> Result<()> {
let workspace_root = std::env::current_dir().ok();
match Config::load_with_layout(
workspace_root.as_deref(),
crate::workspace_layout::current(),
) {
Ok(resolved) => {
println!("Configuration is valid.");
if !resolved.loaded_files.is_empty() {
println!("\nLoaded files:");View on GitHub (pinned to affd8760f4)
Solutions
- Run `astrid config show` without --format (default TOML) to see if the default formatter succeeds.
- Validate the config with `astrid config validate` to find the offending value, then fix config.toml.
- Check for recent manual edits or overrides that introduced unrepresentable values and revert them.
- If the wrapped {e} names a specific key, correct that key's type/value in ~/.astrid/etc/config.toml.
Example fix
// before
let output = resolved
.show(show_format, section)
.map_err(|e| anyhow::anyhow!("failed to format config: {e}"))?;
// after
let output = resolved.show(ShowFormat::Toml, None)
.map_err(|e| anyhow::anyhow!("failed to format config: {e}"))?; Defensive patterns
Strategy: validation
Validate before calling
// preflight: parse the raw TOML before rendering
if let Err(e) = toml::from_str::<toml::Value>(&std::fs::read_to_string("~/.astrid/etc/config.toml")?) {
eprintln!("config.toml not parseable: {e}");
} Try / catch
match resolved.show(fmt, section) {
Err(e) => {
eprintln!("failed to format config ({e}); falling back to TOML");
resolved.show(ShowFormat::Toml, None)
}
ok => ok,
} Prevention
- Run `astrid config validate` after every manual edit to config.toml.
- Prefer `astrid config set` over hand-editing to keep value types valid.
- Keep format strings limited to `json`|`toml` via arg validation.
- Version-control config.toml so bad edits are easy to diff and revert.
When it happens
Trigger: Running `astrid config show --format json` (or toml) where the resolved config contains values that the formatter rejects, or requesting a section that cannot be rendered in the chosen format.
Common situations: Hand-edited config.toml introduces a value type the TOML/JSON serializer cannot represent; a user selects json format but a section only supports TOML rendering; config built from mixed override layers yields an unrepresentable value.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- invalid value for {capsule_id}.{key}: expected one of {}, go
- editor '{editor}' exited with non-zero status
- ASTRID_ENFORCED_DISTRO must not be empty
- Failed to resolve Astrid home: {e}
- {name} not found. Ensure it is installed alongside the astri
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/d381fb871cbd237f.
Report an issue: GitHub.