charmbracelet/glow · error
unable to get cache dir: %w
Error message
unable to get cache dir: %w
What it means
On startup glow resolves a log-file directory with go-app-paths (gap.NewScope(gap.User, "glow").CacheDir(), i.e. ~/.cache/glow on Linux). This error means the user cache directory could not be determined - typically because HOME and XDG_CACHE_HOME are unset or unusable. main() treats it as fatal: it prints the error and exits 1, so glow does not start at all.
Source
Thrown at log.go:16
package main
import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/charmbracelet/log"
gap "github.com/muesli/go-app-paths"
)
func getLogFilePath() (string, error) {
dir, err := gap.NewScope(gap.User, "glow").CacheDir()
if err != nil {
return "", fmt.Errorf("unable to get cache dir: %w", err)
}
return filepath.Join(dir, "glow.log"), nil
}
func setupLog() (func() error, error) {
log.SetOutput(io.Discard)
// Log to file, if set
logFile, err := getLogFilePath()
if err != nil {
return nil, err
}
if err := os.MkdirAll(filepath.Dir(logFile), 0o755); err != nil { //nolint:gosec
// log disabled
return func() error { return nil }, nil //nolint:nilerr
}
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644) //nolint:gosec
if err != nil {
// log disabledView on GitHub (pinned to e3970c813d)
Solutions
- Set HOME to a writable directory: export HOME=/tmp
- Or set XDG_CACHE_HOME=/tmp/cache on Linux so the cache dir resolves
- For service units, add Environment="HOME=/var/lib/glow" to the unit file
- Verify writability afterwards: mkdir -p ~/.cache/glow
Defensive patterns
Strategy: validation
Validate before calling
func cacheDirResolvable() bool {
if dir := os.Getenv("XDG_CACHE_HOME"); dir != "" {
fi, err := os.Stat(dir)
return err == nil && fi.IsDir()
}
return os.Getenv("HOME") != ""
} Prevention
- Always define HOME or XDG_CACHE_HOME in containers, services and cron contexts
- Smoke-test CLI binaries in the same scrubbed environment where they will run
- Treat logging setup as optional in wrappers if logs are not required
When it happens
Trigger: HOME unset and XDG_CACHE_HOME unset (gap cannot compute the cache path); HOME pointing to a path that cannot be resolved; running in an environment where neither variable exists.
Common situations: Docker/OCI scratch or distroless images, systemd units without Environment="HOME=...", cron jobs, CI runners that scrub the environment, minimal sandboxes.
Related errors
- missing markdown source
- unable to set config file: %w
- could not write configuration file: %w
- unable create directory: %w
- unable to create config file: %w
AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15).
Data as JSON: /api/errors/5f7785d08957ba54.
Report an issue: GitHub.