xai-org/grok-build · error

Failed to load config: {e}

Error message

Failed to load config: {e}

What it means

During pager startup, load_effective_config() reads and merges the effective configuration (files + env). Any error it returns is wrapped with this message and propagated as the run's fatal error, because the app cannot start without configuration.

Source

Thrown at crates/codegen/xai-grok-pager/src/app/mod.rs:617

}
/// Main entry point: connect to agent, init terminal, run event loop, restore.
///
/// If a session ID is provided via `--resume` / `--load` / `--continue`, the pager skips the welcome screen and immediately loads that session.
/// The load replays the session's history; sessions not found locally are restored from remote storage.
///
/// Returns `Ok(true)` when the user accepted a pending update.
/// The caller should print a message telling the user to relaunch `grok`.
pub async fn run(
    mut args: PagerArgs,
    bg_update_rx: Option<
        tokio::sync::oneshot::Receiver<Option<xai_grok_update::auto_update::UpdateAvailable>>,
    >,
) -> anyhow::Result<bool> {
    let screen_mode_override = screen_mode_relaunch::take_screen_mode_env_override();
    let cancel = CancellationToken::new();
    let startup_start = std::time::Instant::now();
    let raw_config = xai_grok_shell::config::load_effective_config()
        .map_err(|e| anyhow::anyhow!("Failed to load config: {e}"))?;
    let grok_com_config = match xai_grok_shell::agent::config::Config::new_from_toml_cfg(
        &raw_config,
    ) {
        Ok(c) => c.grok_com_config,
        Err(e) => {
            tracing::warn!(error = %e, "failed to parse config for auth refresh, using defaults");
            xai_grok_shell::auth::GrokComConfig::default()
        }
    };
    if matches!(
        xai_grok_shell::auth::maybe_run_pre_tui_external_login(
            &grok_com_config,
            args.force_login,
            io::stdin().is_terminal(),
        )
        .await?,
        xai_grok_shell::auth::PreTuiLoginOutcome::SignedIn(_)
    ) {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the inner error after 'Failed to load config:' — it names the file/field that failed
  2. Validate the config TOML syntax (e.g. with a TOML linter) and fix schema mismatches
  3. Check file permissions on the config path ($XDG_CONFIG_HOME or ~/.config) and fix ownership
  4. Temporarily move the config file aside to confirm it is the source, then re-add settings incrementally

Example fix

// before: invalid key from an older schema
model = "grok-3"
max_tokin = 4096
// after: corrected key
model = "grok-3"
max_tokens = 4096
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight config check
fn config_ok() -> bool {
    let path = std::env::var("GROK_CONFIG")
        .map(std::path::PathBuf::from)
        .unwrap_or_else(|_| dirs::config_dir().unwrap().join("grok/config.toml"));
    match std::fs::read_to_string(&path) {
        Ok(s) => s.parse::<toml::Value>().is_ok(),
        Err(_) => false,
    }
}

Try / catch

match run().await {
    Err(e) if e.to_string().starts_with("Failed to load config:") => {
        eprintln!("Fix your config first: {e:#}");
        std::process::exit(2);
    }
    other => other.expect("run"),
}

Prevention

When it happens

Trigger: Calling the startup entry point while load_effective_config() fails: malformed TOML in the config file, unreadable file (permissions), invalid env-var overrides, or a bad path given via environment.

Common situations: Typos or invalid syntax in the grok config TOML after a manual edit or version upgrade that changed the schema; XDG_CONFIG_HOME pointing somewhere unwritable; config file owned by root after running with sudo.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/f86bdd439554670a. Report an issue: GitHub.