spacedriveapp/spacedrive · error

SD_LIBRARY_ID environment variable must be set

Error message

SD_LIBRARY_ID environment variable must be set

What it means

gpui-photo-grid is a developer playground app that renders one library as a grid; main() panics at startup unless SD_LIBRARY_ID is set. Unlike SD_SOCKET_ADDR, SD_HTTP_URL, and SD_INITIAL_PATH, which have hard-coded defaults, the library id has no fallback because the view is meaningless without a target library.

Source

Thrown at apps/gpui-photo-grid/src/main.rs:16

mod photo_grid_view;

use gpui::*;
use photo_grid_view::PhotoGridView;
use std::env;
use std::sync::Arc;

fn main() {
    env_logger::init();

    // Get configuration from environment
    let socket_addr = env::var("SD_SOCKET_ADDR").unwrap_or_else(|_| "127.0.0.1:6969".to_string());

    let http_url = env::var("SD_HTTP_URL").unwrap_or_else(|_e| "http://127.0.0.1:56851".to_string());

    let library_id = env::var("SD_LIBRARY_ID").expect("SD_LIBRARY_ID environment variable must be set");

    let initial_path = env::var("SD_INITIAL_PATH").unwrap_or_else(|_e| "/Users/jamespine/Desktop".to_string());

    println!("Starting GPUI Photo Grid");
    println!("  Socket: {}", socket_addr);
    println!("  HTTP: {}", http_url);
    println!("  Library: {}", library_id);
    println!("  Path: {}", initial_path);

    // Create HTTP client for image loading
    let http_client = Arc::new(
        reqwest_client::ReqwestClient::user_agent("spacedrive-gpui")
            .expect("Failed to create HTTP client"),
    );

    Application::new()
        .with_http_client(http_client)
        .run(move |cx: &mut App| {

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Set the variable to an existing library id: SD_LIBRARY_ID=<uuid> cargo run -p gpui-photo-grid
  2. List libraries first: cargo run --bin sd-cli -- libraries list (or the equivalent CLI command) to copy the id
  3. Check the repo justfile/scripts for the canonical launch command that wires all SD_* variables

Example fix

// before: silent requirement, panics with a bare expect
let library_id = env::var("SD_LIBRARY_ID").expect("SD_LIBRARY_ID environment variable must be set");

// after: actionable startup error listing available ids
let library_id = env::var("SD_LIBRARY_ID").unwrap_or_else(|_| {
    eprintln!("SD_LIBRARY_ID is required. Get ids via: sd-cli libraries list");
    std::process::exit(2);
});
Defensive patterns

Strategy: validation

Validate before calling

let library_id = match env::var("SD_LIBRARY_ID") {
    Ok(v) if !v.trim().is_empty() => v,
    _ => {
        eprintln!("SD_LIBRARY_ID is required (get ids via: sd-cli libraries list)");
        std::process::exit(2);
    }
};

Prevention

When it happens

Trigger: cargo run inside apps/gpui-photo-grid without environment variables; launching the binary directly instead of through the repo helper/just recipe that injects daemon env; running against a daemon whose libraries were wiped.

Common situations: First run of the playground app on a fresh clone; CI or scripted runs that only set the other three SD_* variables.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/86e6a5ac367d9e3c. Report an issue: GitHub.