block/buzz · error · anyhow::Error

must be set for storage-snapshot

Error message

{name} must be set for storage-snapshot

What it means

storage_config_from_env builds the S3 MediaConfig for the snapshot and requires BUZZ_S3_BUCKET to be present in the environment; unlike endpoint/keys/region it has no default. The `required` closure maps a failed std::env::var lookup to this error naming the missing variable.

Solutions

  1. Export BUZZ_S3_BUCKET (and endpoint/keys: BUZZ_S3_ENDPOINT, BUZZ_S3_ACCESS_KEY, BUZZ_S3_SECRET_KEY) before running the command, e.g. `set -a; . ./.env; set +a`.
  2. Run the command in the same environment/worker as the relay so its env is inherited.
  3. Fix the service unit/cron file to include an EnvironmentFile with the media settings.
  4. Read the error's {name} to confirm exactly which variable is missing, then set it.

Example fix

// before
buzz-admin storage-snapshot --max-objects 1000000
// after (load .env first)
set -a; . ./.env; set +a
buzz-admin storage-snapshot --max-objects 1000000
Defensive patterns

Strategy: validation

Validate before calling

for var in ["BUZZ_S3_BUCKET", "BUZZ_S3_ENDPOINT", "BUZZ_S3_ACCESS_KEY", "BUZZ_S3_SECRET_KEY"] {
    if std::env::var(var).is_err() {
        return Err(format!("{var} must be set for storage-snapshot"));
    }
}

Try / catch

match cmd_storage_snapshot(max_objects).await {
    Err(e) if e.to_string().ends_with("must be set for storage-snapshot") => {
        eprintln!("Hint: source .env before running, e.g. `set -a; . ./.env; set +a`");
        return Err(e);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `buzz-admin storage-snapshot` without BUZZ_S3_BUCKET exported (and, in practice, the other S3 settings also unset, since the bucket is the only hard-required one). std::env::var("BUZZ_S3_BUCKET") returns Err (missing or non-UTF8) and the closure formats this message.

Common situations: Running the admin command in a shell where .env was not sourced, running via cron/systemd with a minimal environment, or forgetting that storage-snapshot needs media config even though it only lists the bucket.

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@ef2aa1ae38 (2026-09-20). Data as JSON: /api/errors/62a9cf44ed632905. Report an issue: GitHub.

Appendix: source

Thrown at crates/buzz-admin/src/main.rs:292

    fold: FoldFuture,
    persist: Persist,
) -> Result<(BucketSnapshot, i64)>
where
    FoldFuture: Future<Output = std::result::Result<BucketSnapshot, SweepError>>,
    Persist: FnOnce(serde_json::Value, i64) -> PersistFuture,
    PersistFuture: Future<Output = Result<()>>,
{
    let started = Instant::now();
    let snapshot = fold.await?;
    let duration_ms = i64::try_from(started.elapsed().as_millis()).unwrap_or(i64::MAX);
    let encoded = serde_json::to_value(&snapshot)?;
    persist(encoded, duration_ms).await?;
    Ok((snapshot, duration_ms))
}

fn storage_config_from_env() -> Result<MediaConfig> {
    let required = |name: &str| {
        std::env::var(name).map_err(|_| anyhow::anyhow!("{name} must be set for storage-snapshot"))
    };
    let addressing_style = std::env::var("BUZZ_S3_ADDRESSING_STYLE")
        .unwrap_or_else(|_| "path".to_string())
        .parse::<S3AddressingStyle>()
        .map_err(anyhow::Error::msg)?;
    Ok(MediaConfig {
        s3_endpoint: std::env::var("BUZZ_S3_ENDPOINT").unwrap_or_default(),
        s3_access_key: std::env::var("BUZZ_S3_ACCESS_KEY").unwrap_or_default(),
        s3_secret_key: std::env::var("BUZZ_S3_SECRET_KEY").unwrap_or_default(),
        s3_bucket: required("BUZZ_S3_BUCKET")?,
        s3_region: std::env::var("BUZZ_S3_REGION").unwrap_or_else(|_| "us-east-1".to_string()),
        s3_addressing_style: addressing_style,
        max_image_bytes: 1,
        max_gif_bytes: 1,
        max_video_bytes: 1,
        max_file_bytes: 1,
        public_base_url: "http://storage-snapshot.invalid/media".to_string(),
        upload_records_enabled: false,

View on GitHub (pinned to ef2aa1ae38)