astrid-runtime/astrid · error · anyhow::Error

resolve AstridHome: {e}

Error message

resolve AstridHome: {e}

What it means

`load_gateway_config` resolves the AstridHome directory layout via `astrid_core::dirs::AstridHome::resolve()` to locate `etc/gateway-http.toml`. If home resolution itself fails (cannot determine or create the astrid home directories), this error wraps the cause. A missing gateway-http.toml is fine (returns Ok(None)); only a broken home resolution is fatal.

Source

Thrown at crates/astrid-daemon/src/lib.rs:481

///
/// # Errors
///
/// Always returns an explicit unsupported-platform error.
#[cfg(not(unix))]
#[expect(
    clippy::unused_async,
    reason = "the cross-platform daemon entry point remains async even when startup is unsupported"
)]
pub async fn run() -> Result<()> {
    anyhow::bail!("native Astrid daemon startup is not yet supported on this platform")
}

/// Load `etc/gateway-http.toml`. Returns `Ok(None)` when the file
/// doesn't exist (single-tenant default).
#[cfg(unix)]
async fn load_gateway_config() -> Result<Option<astrid_gateway::GatewayConfig>> {
    let home = astrid_core::dirs::AstridHome::resolve()
        .map_err(|e| anyhow::anyhow!("resolve AstridHome: {e}"))?;
    let path = home.etc_dir().join("gateway-http.toml");
    let text = match tokio::fs::read_to_string(&path).await {
        Ok(b) => b,
        Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
        Err(e) => return Err(anyhow::anyhow!("read {}: {e}", path.display())),
    };
    let cfg: astrid_gateway::GatewayConfig =
        toml::from_str(&text).context("parse gateway-http.toml")?;
    cfg.validate().context("validate gateway-http.toml")?;
    Ok(Some(cfg))
}

#[cfg(unix)]
fn spawn_gateway(
    cfg: astrid_gateway::GatewayConfig,
    kernel: &std::sync::Arc<astrid_kernel::Kernel>,
) -> Result<std::sync::Arc<tokio::sync::Notify>> {
    // Plumb four kernel handles into the gateway:

View on GitHub (pinned to affd8760f4)

Solutions

  1. Check the wrapped `{e}` for which home path failed.
  2. Ensure HOME (and relevant XDG vars) is set to an existing, writable directory for the daemon process.
  3. Pre-create or fix permissions on the astrid home directory.

Example fix

// systemd unit before
[Service]
ExecStart=/usr/bin/astrid-daemon
// after
[Service]
Environment=HOME=/var/lib/astrid
ExecStart=/usr/bin/astrid-daemon
Defensive patterns

Strategy: validation

Validate before calling

// shell
: "${HOME:?HOME must be set for astrid daemon}" && [ -d "$HOME" ] || { echo "HOME not a directory" >&2; exit 1; }

Try / catch

// rust
match load_gateway_config().await {
    Ok(cfg) => { /* Ok(None) means no gateway-http.toml — fine */ }
    Err(e) => { eprintln!("gateway config: {e:#}"); }
}

Prevention

When it happens

Trigger: Calling `load_gateway_config()` (from daemon `run()`, unix only) when `AstridHome::resolve()` errors — e.g. HOME is unset/invalid on unix, or the home directory tree cannot be created.

Common situations: Running the daemon under systemd/CI with HOME unset; XDG/home variables pointing at non-existent or unwritable paths.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/ca5449897b90f0ad. Report an issue: GitHub.