{"record":{"id":"24afe9627f1ee1ac","repo":"xai-org/grok-build","slug":"failed-to-load-config-e-24afe9","errorCode":null,"errorMessage":"Failed to load config: {e}","messagePattern":"Failed to load config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/headless.rs","lineNumber":783,"sourceCode":"\n    let cwd = match options.cwd {\n        None => std::env::current_dir()?,\n        Some(ref p) => dunce::canonicalize(p)?,\n    };\n\n    let mut emitter = HeadlessEmitter::new(options.output_format, options.json_schema.is_some());\n\n    if options.include_partial_messages\n        && options.output_format != OutputFormat::StreamingMessagesJson\n    {\n        eprintln!(\n            \"warning: --include-partial-messages only affects --output-format streaming-messages-json; ignoring it\"\n        );\n    }\n\n    let t_spawn = Instant::now();\n    let raw_config = xai_grok_shell::config::load_effective_config()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load config: {e}\"))?;\n    let mut agent_config = AgentConfig::new_from_toml_cfg(&raw_config)\n        .map_err(|e| anyhow::anyhow!(\"Failed to create agent config: {e}\"))?;\n\n    // Only canonical tokens are stamped early; remapped menu ids need the post-session catalog resolve below\n    if let Some(ref token) = options.reasoning_effort\n        && let Some(effort) = parse_canonical_effort_token(token)\n    {\n        agent_config.reasoning_effort_override = Some(effort);\n    }\n    // Stamp `-m` early so the initial system prompt uses it, not a later SetSessionModel.\n    if let Some(ref model) = options.model {\n        agent_config.default_model_override = Some(model.clone());\n    }\n\n    agent_config.resolve_runtime_fields(&xai_grok_shell::agent::config::RuntimeResolutionContext {\n        raw_config: &raw_config,\n        remote_settings: None,\n        is_headless: true,","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/headless.rs#L765-L801","documentation":"run_single_turn wraps any failure from xai_grok_shell::config::load_effective_config() in an anyhow context 'Failed to load config: {e}'. It means the effective configuration (TOML config file plus environment overrides) could not be read, found, or parsed, so no agent session can start.","triggerScenarios":"Calling run_single_turn (headless single-turn run) when load_effective_config() fails: the config file path is set but missing/unreadable, the TOML is syntactically invalid, or an env-var override has an invalid value.","commonSituations":"First run with no config file at the expected location; hand-edited config.toml with a typo; XDG_CONFIG_HOME or a config-path env var pointing to the wrong directory; config written by a newer version with unknown keys/types.","solutions":["Read the inner {e} message; it states the exact file path and parse error","Run with an explicitly valid config path / restore a known-good config.toml","Validate the TOML with a linter (e.g. taplo) before restarting","Reinstall or regenerate default config via the shell's init command if the file is corrupted"],"exampleFix":"// before: blindly loading config\nlet raw_config = xai_grok_shell::config::load_effective_config()?;\n// after: check existence and fail with an actionable message\nlet path = xai_grok_shell::config::default_config_path();\nanyhow::ensure!(path.exists(), \"config not found at {}; run the init command\", path.display());\nlet raw_config = xai_grok_shell::config::load_effective_config()?;","handlingStrategy":"validation","validationCode":"let path = xai_grok_shell::config::default_config_path();\nif !path.exists() {\n    eprintln!(\"config missing at {} — run init or set the config path\", path.display());\n    std::process::exit(2);\n}\nif let Err(e) = std::fs::read_to_string(&path).and_then(|s| toml::from_str::<toml::Value>(&s).map_err(std::io::Error::other).map(|_| ())) {\n    eprintln!(\"config invalid: {e}\");\n    std::process::exit(2);\n}","typeGuard":"fn config_readable(path: &std::path::Path) -> bool {\n    path.is_file() && std::fs::read_to_string(path)\n        .map(|s| toml::from_str::<toml::Value>(&s).is_ok())\n        .unwrap_or(false)\n}","tryCatchPattern":"match xai_grok_shell::config::load_effective_config() {\n    Ok(cfg) => cfg,\n    Err(e) => { eprintln!(\"Failed to load config: {e:#}\"); std::process::exit(2); }\n}","preventionTips":["Validate config.toml with a TOML linter in CI before deploys","Regenerate defaults after upgrading the binary","Never hand-edit config without re-validating","Pin config path via env var explicitly in scripts"],"tags":["config","toml","rust","startup"],"backgroundTag":"config-load-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}