{"record":{"id":"42db93c00c995f4e","repo":"benbjohnson/litestream","slug":"cannot-expand-path-s-no-home-directory-available","errorCode":null,"errorMessage":"cannot expand path %s, no home directory available","messagePattern":"cannot expand path (.+?), no home directory available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":2132,"sourceCode":"\n// expand returns an absolute path for s.\n// It also strips SQLite connection string prefixes (sqlite://, sqlite3://).\nfunc expand(s string) (string, error) {\n\t// Strip SQLite connection string prefixes if present.\n\ts = StripSQLitePrefix(s)\n\n\t// Just expand to absolute path if there is no home directory prefix.\n\tprefix := \"~\" + string(os.PathSeparator)\n\tif s != \"~\" && !strings.HasPrefix(s, prefix) {\n\t\treturn filepath.Abs(s)\n\t}\n\n\t// Look up home directory.\n\tu, err := user.Current()\n\tif err != nil {\n\t\treturn \"\", err\n\t} else if u.HomeDir == \"\" {\n\t\treturn \"\", fmt.Errorf(\"cannot expand path %s, no home directory available\", s)\n\t}\n\n\t// Return path with tilde replaced by the home directory.\n\tif s == \"~\" {\n\t\treturn u.HomeDir, nil\n\t}\n\treturn filepath.Join(u.HomeDir, strings.TrimPrefix(s, prefix)), nil\n}\n\n// StripSQLitePrefix removes SQLite connection string prefixes (sqlite://, sqlite3://)\n// from the given path. This allows users to use standard connection string formats\n// across their tooling while Litestream extracts just the file path.\nfunc StripSQLitePrefix(s string) string {\n\tif len(s) < 9 || s[0] != 's' {\n\t\treturn s\n\t}\n\tfor _, prefix := range []string{\"sqlite3://\", \"sqlite://\"} {\n\t\tif strings.HasPrefix(s, prefix) {","sourceCodeStart":2114,"sourceCodeEnd":2150,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L2114-L2150","documentation":"expandTilde (called when expanding a leading `~` in a config path) failed to determine the current user's home directory: user.Current() succeeded but returned an empty HomeDir, so there is no directory to substitute for the tilde.","triggerScenarios":"A config value or flag path starts with `~` and Litestream runs in an environment where the OS user has no resolvable home directory (e.g. certain containers, service accounts, or stripped /etc/passwd entries).","commonSituations":"Running litestream in a scratch Docker image as a non-existent UID; systemd services with no HOME set for the user; CI runners with minimal user records.","solutions":["Replace `~` in the config path with the absolute home directory, e.g. `/home/litestream/data`.","Ensure the process runs as a user that exists in /etc/passwd with a valid home directory.","Run with HOME/userdb available in the container image, or pass an absolute path via flag/config."],"exampleFix":"// before\npath: ~/data/db.sqlite\n// after\npath: /home/litestream/data/db.sqlite","handlingStrategy":"fallback","validationCode":"// Prefer absolute paths in generated configs\nu, err := user.Current()\nif err != nil || u.HomeDir == \"\" {\n    return fmt.Errorf(\"cannot expand ~; use absolute path\")\n}","typeGuard":null,"tryCatchPattern":"if err := startLitestream(); err != nil {\n    if strings.Contains(err.Error(), \"no home directory available\") {\n        // rewrite config paths to absolute and retry\n    }\n}","preventionTips":["Generate configs with absolute paths, never `~`.","In containers, run as a user defined in /etc/passwd with a valid home.","Set HOME explicitly in unit files if tilde expansion is needed."],"tags":["path","home-directory","config","unix"],"backgroundTag":"missing-env-var","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}