tursodatabase/turso · error
Could not determine home directory
Error message
Could not determine home directory
What it means
The tursopg CLI resolves the user's home directory once into the HOME_DIR LazyLock static (postgres/cli/main.rs:54-55), used to build ~/.tursopg_history for readline history (postgres/cli/main.rs:57, 926). dirs::home_dir() returns None when $HOME is unset or empty and no passwd entry supplies it, and the LazyLock's expect("Could not determine home directory") panics the entire process at startup.
Source
Thrown at postgres/cli/main.rs:55
use std::io::{IsTerminal, Write};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, LazyLock};
use std::time::Instant;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;
use turso_core::{DatabaseOpts, LimboError, OpenFlags, Statement, Value};
use turso_pg::Connection;
use turso_pg_server::TursoPgServer;
// ---------------------------------------------------------------------------
// Statics
// ---------------------------------------------------------------------------
pub static HOME_DIR: LazyLock<PathBuf> =
LazyLock::new(|| dirs::home_dir().expect("Could not determine home directory"));
pub static HISTORY_FILE: LazyLock<PathBuf> = LazyLock::new(|| HOME_DIR.join(".tursopg_history"));
const PROMPT: &str = "tursopg> ";
const PROMPT_CONT: &str = "tursopg-> ";
// ---------------------------------------------------------------------------
// CLI options
// ---------------------------------------------------------------------------
#[derive(Parser, Debug)]
#[command(name = "tursopg")]
#[command(author, version, about = "PostgreSQL-compatible micro database")]
struct Opts {
#[clap(index = 1, help = "Database file", default_value = ":memory:")]
database: Option<PathBuf>,
#[clap(index = 2, help = "Optional SQL command to execute")]View on GitHub (pinned to c1e5928725)
Solutions
- Set HOME to a writable directory before launch: export HOME=/tmp, or docker run -e HOME=/tmp tursopg ...
- Run under a user with a valid passwd entry (proper USER directive plus passwd file in the image).
- File an issue against tursopg: a missing home directory should skip history persistence, not panic the CLI.
Example fix
# before: panics - no HOME in the image FROM scratch COPY tursopg / ENTRYPOINT ["/tursopg"] # after: provide a home directory FROM scratch COPY tursopg / ENV HOME=/tmp ENTRYPOINT ["/tursopg"]
Defensive patterns
Strategy: validation
Validate before calling
# Wrapper check before invoking the CLI:
import os, subprocess, sys
if not os.environ.get("HOME"):
sys.exit("refusing to start tursopg: HOME is not set (CLI panics)")
subprocess.run(["tursopg", *sys.argv[1:]]) Prevention
- Set ENV HOME=/tmp (or a real user home) in Dockerfiles and OCI images.
- In systemd units and cron entries, add Environment="HOME=..." explicitly.
- For arbitrary-UID deployments, provide an /etc/passwd (or libnss) entry for the UID.
- Include tursopg startup in container smoke tests so this fails in CI, not production.
When it happens
Trigger: Running the tursopg binary with HOME unset or empty: env -i tursopg, minimal Docker images with no HOME configured, Kubernetes pods, systemd units without Environment="HOME=...", cron jobs, or a UID with no /etc/passwd entry.
Common situations: Distroless/scratch container images, CI runners that scrub the environment, running as an arbitrary UID not present in /etc/passwd, deployment platforms that drop HOME.
Related errors
- Error setting Ctrl-C handler
- Unexpected row for INSERT
- Failed to read manual page: {}
- Manual page not found: {page_name}
- failed to generate random bytes
AI-assisted analysis of tursodatabase/turso@c1e5928725 (2026-08-20).
Data as JSON: /api/errors/e74c4b2049d81afa.
Report an issue: GitHub.