dbt-labs/dbt-core · error

Unable to get home directory

Error message

Unable to get home directory

What it means

Raised in lease_file_path while resolving where to write the dbt lease file: the user's home directory could not be determined from the environment (HOME/USERPROFILE unset or inaccessible via dirs), so the lease file path cannot be constructed.

Solutions

  1. Set HOME (or the platform equivalent) in the environment
  2. Run dbt from a context with a resolvable user home directory
  3. Ensure the process is not running with an intentionally emptied environment
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/dbt-common/src/lease.rs:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/a06fe53b64dc2b87. Report an issue: GitHub.

Appendix: source

Thrown at crates/dbt-common/src/lease.rs:60

    }
}

/// Acquires a lease on the given directory and spawns a background renewal task.
/// Returns a [`LeaseGuard`] that releases the lease when dropped.
/// Uses default values for ttl and the renewal interval.
pub async fn acquire_lease(project_dir: &Path, relative_dir: &Path) -> FsResult<LeaseGuard> {
    // default ttl and renewal
    let lease_ttl: Duration = Duration::from_millis(2000);
    let renewal_interval: Duration = Duration::from_millis(500);
    acquire_lease_with_renewal(project_dir, relative_dir, lease_ttl, renewal_interval).await
}

/// Returns the lease file path for a given directory name:
/// `~/.dbt/leases/.dbt_lease_{hash of <project_root>/<dir_name>/}`.
fn lease_file_path(project_root: &Path, dir_name: &Path) -> PathBuf {
    let dir_path = DbtPath::from(project_root.join(dir_name));

    let home_dir = DbtPath::from(dirs::home_dir().expect("Unable to get home directory"));
    debug_assert!(home_dir.is_absolute());

    let dbt_leases_dir = home_dir.join(".dbt/leases");
    create_dir_all(&dbt_leases_dir).ok();

    // Hash the directory that we are holding a lease on.
    let mut hasher = Sha256::new();
    hasher.update(dir_path.to_string_lossy().as_bytes());
    let hash = hasher.finalize();
    let hex = format!("{:x}", hash);
    let hash_string = hex[..10.min(hex.len())].to_string();

    dbt_leases_dir
        .join(format!(".dbt_lease_{hash_string}"))
        .to_path_buf()
}

impl LeaseHandler {

View on GitHub (pinned to 0267ce9170)