t8y2/dbx · critical

Failed to create data directory

Error message

Failed to create data directory

What it means

On startup dbx-web resolves its data directory (DBX_DATA_DIR or ~/.dbx-web) and calls std::fs::create_dir_all with expect(). If the directory cannot be created, the process panics before serving any traffic.

Source

Thrown at crates/dbx-web/src/main.rs:300

}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_default_env()
                .unwrap_or_else(|_| "dbx_web=info,tower_http=info".parse().unwrap()),
        )
        .init();

    rustls::crypto::aws_lc_rs::default_provider().install_default().expect("Failed to install rustls crypto provider");

    // Data directory
    let data_dir = std::env::var("DBX_DATA_DIR").map(std::path::PathBuf::from).unwrap_or_else(|_| {
        let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
        std::path::PathBuf::from(home).join(".dbx-web")
    });
    std::fs::create_dir_all(&data_dir).expect("Failed to create data directory");

    let app_state = {
        let db_path = data_dir.join("dbx.db");
        let storage = Storage::open(&db_path).await.expect("Failed to open storage");
        storage.migrate_from_json(&data_dir).await.expect("Failed to migrate JSON data");

        // Initialize core dialect registry and load external plugin dialects
        register_core_dialects();
        let registry = DialectRegistry::global();
        let plugin_dirs = vec![data_dir.join("plugins").join("dialects")];
        let load_result = DialectPluginLoader::scan_and_load(registry, &plugin_dirs);
        log::info!(
            "Dialect plugins loaded: {} success, {} errors, {} skipped",
            load_result.loaded.len(),
            load_result.errors.len(),
            load_result.skipped.len()
        );

View on GitHub (pinned to c0390bff16)

Solutions

  1. Set DBX_DATA_DIR to a writable directory the process user can create and write.
  2. Ensure the path is not occupied by a file and the parent directory is writable (check permissions/ownership).
  3. In containers, mount a writable volume at the data directory (e.g., docker -v dbx-data:/data -e DBX_DATA_DIR=/data).
  4. Replace expect() with graceful error handling that logs the OS error and exits with a clear message.

Example fix

// before
std::fs::create_dir_all(&data_dir).expect("Failed to create data directory");
// after
if let Err(e) = std::fs::create_dir_all(&data_dir) {
    eprintln!("Failed to create data directory {}: {e}", data_dir.display());
    std::process::exit(1);
}
Defensive patterns

Strategy: validation

Validate before calling

fn data_dir_writable(path: &std::path::Path) -> bool {
    if path.is_file() { return false; }
    std::fs::create_dir_all(path)
        .and_then(|_| std::fs::write(path.join(".write_test"), b"ok"))
        .map(|_| true)
        .unwrap_or(false)
}

Try / catch

// match on the fs result and exit with a clear message
if let Err(e) = std::fs::create_dir_all(&data_dir) {
    eprintln!("Failed to create data directory {}: {e}", data_dir.display());
    std::process::exit(1);
}

Prevention

When it happens

Trigger: std::fs::create_dir_all(&data_dir) fails due to missing write permission on the parent, a file existing at the data_dir path, a read-only filesystem, or an invalid HOME/DBX_DATA_DIR path.

Common situations: Running in a container with a read-only root filesystem and no DBX_DATA_DIR volume; HOME pointing to a non-writable path; data_dir path occupied by a regular file; Docker/Kubernetes volume mounted with wrong ownership.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/50bd2ae8b14de445. Report an issue: GitHub.