block/buzz · error · anyhow::Error

cannot derive community host; pass --host or set RELAY_URL

Error message

cannot derive community host; pass --host or set RELAY_URL

What it means

buzz-deletion tooling is tenant-scoped: every purge operation needs to know which community (host) it acts on. The host comes from the --host flag when given (non-empty after trim), otherwise it is derived from RELAY_URL via buzz_core::tenant::relay_url_authority. When neither --host nor a non-empty RELAY_URL is available, resolution bails with this error before any database work starts.

Solutions

  1. Pass the host explicitly: --host localhost:3000 (authority form: host plus non-default port).
  2. Or export RELAY_URL=ws://localhost:3000 in the job's environment.
  3. For cron/systemd, set the variable in the unit/job definition rather than relying on the login shell.
  4. Prefer --host in automation — it is immune to URL-parse edge cases entirely.

Example fix

# before
./bin/run-deletion purge-old --days 30          # no RELAY_URL in env -> cannot derive community host
# after
./bin/run-deletion purge-old --days 30 --host localhost:3000
# or: export RELAY_URL=ws://localhost:3000 && ./bin/run-deletion purge-old --days 30
Defensive patterns

Strategy: validation

Validate before calling

# in automation, fail fast when neither route to the host exists
if [ -z "${RELAY_URL:-}" ] && [ -z "${DELETION_HOST:-}" ]; then
  echo 'deletion needs --host or RELAY_URL' >&2; exit 3
fi

Prevention

When it happens

Trigger: Invoking the deletion CLI/library entry point in an environment with no RELAY_URL (bare cron job, minimal container) and without passing --host; RELAY_URL set to an empty string or whitespace, which the trim+filter treats as absent.

Common situations: Scheduled cleanup jobs that inherit a stripped environment; scripts written against a dev box (where the shell had RELAY_URL exported) later run in CI; .env not sourced in the deletion tool's working directory.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of block/buzz@dad5a33865 (2026-08-20). Data as JSON: /api/errors/7bf2568e6fdb1fe9. Report an issue: GitHub.

Appendix: source

Thrown at crates/buzz-deletion/src/lib.rs:521

            anyhow::bail!("database-only command reached full-service dispatcher")
        }
    }
}

fn resolve_submit_host(host: Option<&str>, relay_url: Option<&str>) -> Result<String> {
    if let Some(host) = host {
        let host = host.trim();
        if host.is_empty() {
            anyhow::bail!("--host must not be empty");
        }
        return Ok(host.to_owned());
    }

    let relay_url = relay_url
        .map(str::trim)
        .filter(|value| !value.is_empty())
        .ok_or_else(|| {
            anyhow::anyhow!("cannot derive community host; pass --host or set RELAY_URL")
        })?;
    let host = buzz_core::tenant::relay_url_authority(relay_url);
    if host.is_empty() {
        anyhow::bail!(
            "cannot derive community host from RELAY_URL; pass --host or set a valid RELAY_URL"
        );
    }
    Ok(host)
}

async fn connect_store() -> Result<DeletionStore> {
    let database_url = required_env("DATABASE_URL")?;
    let db = Db::new(
        &DbConfig {
            database_url,
            max_connections: env_parse("BUZZ_DB_POOL_SIZE", 20),
            ..DbConfig::default()
        }

View on GitHub (pinned to dad5a33865)