{"record":{"id":"d381fb871cbd237f","repo":"astrid-runtime/astrid","slug":"failed-to-format-config-e","errorCode":null,"errorMessage":"failed to format config: {e}","messagePattern":"failed to format config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/config.rs","lineNumber":21,"sourceCode":"use anyhow::Result;\nuse astrid_config::{Config, ResolvedConfig, ShowFormat};\n\n/// Show the resolved configuration with source annotations.\npub(crate) fn show_config(format: &str, section: Option<&str>) -> Result<()> {\n    let workspace_root = std::env::current_dir().ok();\n    let resolved = Config::load_with_layout(\n        workspace_root.as_deref(),\n        crate::workspace_layout::current(),\n    )?;\n\n    let show_format = match format {\n        \"json\" => ShowFormat::Json,\n        _ => ShowFormat::Toml,\n    };\n\n    let output = resolved\n        .show(show_format, section)\n        .map_err(|e| anyhow::anyhow!(\"failed to format config: {e}\"))?;\n\n    println!(\"{output}\");\n    Ok(())\n}\n\n/// Validate the current configuration.\n#[expect(clippy::unnecessary_wraps)]\npub(crate) fn validate_config() -> Result<()> {\n    let workspace_root = std::env::current_dir().ok();\n\n    match Config::load_with_layout(\n        workspace_root.as_deref(),\n        crate::workspace_layout::current(),\n    ) {\n        Ok(resolved) => {\n            println!(\"Configuration is valid.\");\n            if !resolved.loaded_files.is_empty() {\n                println!(\"\\nLoaded files:\");","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/config.rs#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet output = resolved\n    .show(show_format, section)\n    .map_err(|e| anyhow::anyhow!(\"failed to format config: {e}\"))?;\n// after\nlet output = resolved.show(ShowFormat::Toml, None)\n    .map_err(|e| anyhow::anyhow!(\"failed to format config: {e}\"))?;","handlingStrategy":"validation","validationCode":"// preflight: parse the raw TOML before rendering\nif let Err(e) = toml::from_str::<toml::Value>(&std::fs::read_to_string(\"~/.astrid/etc/config.toml\")?) {\n    eprintln!(\"config.toml not parseable: {e}\");\n}","typeGuard":null,"tryCatchPattern":"match resolved.show(fmt, section) {\n    Err(e) => {\n        eprintln!(\"failed to format config ({e}); falling back to TOML\");\n        resolved.show(ShowFormat::Toml, None)\n    }\n    ok => ok,\n}","preventionTips":["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."],"tags":["config","formatting","serialization","cli"],"backgroundTag":"invalid-config-value","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}