{"record":{"id":"e74c4b2049d81afa","repo":"tursodatabase/turso","slug":"could-not-determine-home-directory-e74c4b","errorCode":null,"errorMessage":"Could not determine home directory","messagePattern":"Could not determine home directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"postgres/cli/main.rs","lineNumber":55,"sourceCode":"use std::io::{IsTerminal, Write};\nuse std::path::{Path, PathBuf};\nuse std::sync::atomic::{AtomicUsize, Ordering};\nuse std::sync::{Arc, LazyLock};\nuse std::time::Instant;\nuse tracing_appender::non_blocking::WorkerGuard;\nuse tracing_subscriber::layer::SubscriberExt;\nuse tracing_subscriber::util::SubscriberInitExt;\nuse tracing_subscriber::EnvFilter;\nuse turso_core::{DatabaseOpts, LimboError, OpenFlags, Statement, Value};\nuse turso_pg::Connection;\nuse turso_pg_server::TursoPgServer;\n\n// ---------------------------------------------------------------------------\n// Statics\n// ---------------------------------------------------------------------------\n\npub static HOME_DIR: LazyLock<PathBuf> =\n    LazyLock::new(|| dirs::home_dir().expect(\"Could not determine home directory\"));\n\npub static HISTORY_FILE: LazyLock<PathBuf> = LazyLock::new(|| HOME_DIR.join(\".tursopg_history\"));\n\nconst PROMPT: &str = \"tursopg> \";\nconst PROMPT_CONT: &str = \"tursopg-> \";\n\n// ---------------------------------------------------------------------------\n// CLI options\n// ---------------------------------------------------------------------------\n\n#[derive(Parser, Debug)]\n#[command(name = \"tursopg\")]\n#[command(author, version, about = \"PostgreSQL-compatible micro database\")]\nstruct Opts {\n    #[clap(index = 1, help = \"Database file\", default_value = \":memory:\")]\n    database: Option<PathBuf>,\n\n    #[clap(index = 2, help = \"Optional SQL command to execute\")]","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/postgres/cli/main.rs#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: panics - no HOME in the image\nFROM scratch\nCOPY tursopg /\nENTRYPOINT [\"/tursopg\"]\n\n# after: provide a home directory\nFROM scratch\nCOPY tursopg /\nENV HOME=/tmp\nENTRYPOINT [\"/tursopg\"]","handlingStrategy":"validation","validationCode":"# Wrapper check before invoking the CLI:\nimport os, subprocess, sys\nif not os.environ.get(\"HOME\"):\n    sys.exit(\"refusing to start tursopg: HOME is not set (CLI panics)\")\nsubprocess.run([\"tursopg\", *sys.argv[1:]])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","tursopg","home-directory","environment","container","rust","panic"],"backgroundTag":"missing-home-env-var","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}