anomalyco/sst · critical

panic(err)

Error message

panic(err)

What it means

The SST CLI resolves its global config directory at package init time by calling os.UserConfigDir(). On Unix this requires either $XDG_CONFIG_HOME or $HOME to be set; on Windows it requires %AppData%. If none can be determined, Go returns an error and the package panics immediately at startup (var initializer), before any SST command runs.

Source

Thrown at pkg/global/global.go:24

	"github.com/pulumi/pulumi/sdk/v3"
	"github.com/sst/sst/v3/pkg/flag"
)

var PULUMI_VERSION = "v" + sdk.Version.String()
var BUN_VERSION = func() string {
	if flag.SST_BUN_VERSION != "" {
		return flag.SST_BUN_VERSION
	}
	return "1.2.1"
}()

const UV_VERSION = "0.3.2"

var configDir = (func() string {
	home, err := os.UserConfigDir()
	if err != nil {
		panic(err)
	}
	result := filepath.Join(home, "sst")
	os.MkdirAll(result, 0755)
	os.MkdirAll(filepath.Join(result, "bin"), 0755)
	return result
}())

func ConfigDir() string {
	return configDir
}

func BinPath() string {
	return filepath.Join(configDir, "bin")
}

func CertPath() string {
	return filepath.Join(configDir, "cert")
}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Set HOME (or XDG_CONFIG_HOME on Unix) to a writable directory before running the sst CLI, e.g. `export HOME=/root` or `export XDG_CONFIG_HOME=/tmp/.config`
  2. In Docker, add `ENV HOME=/root` (and `RUN mkdir -p /root/.config`) to the image
  3. For cron/systemd, pass `Environment=HOME=/home/USER` or wrap the command in a login shell (`bash -lc 'sst deploy'`)
  4. On Windows, ensure the AppData environment variable is defined for the process context running sst

Example fix

// before (Dockerfile)
FROM alpine
CMD ["sst", "deploy"]
// after
FROM alpine
ENV HOME=/root XDG_CONFIG_HOME=/root/.config
RUN mkdir -p /root/.config
CMD ["sst", "deploy"]
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "${HOME:-}" ] && [ -z "${XDG_CONFIG_HOME:-}" ]; then echo 'HOME or XDG_CONFIG_HOME must be set for sst'; exit 1; fi

Try / catch

// Go callers importing pkg/global cannot catch an init-time panic; validate env before exec'ing sst:
if os.Getenv("HOME") == "" && os.Getenv("XDG_CONFIG_HOME") == "" && os.Getenv("AppData") == "" {
    return fmt.Errorf("cannot run sst: HOME/XDG_CONFIG_HOME/AppData not set")
}

Prevention

When it happens

Trigger: Running any sst CLI command in an environment where os.UserConfigDir() fails: $HOME and $XDG_CONFIG_HOME both unset/empty (Linux/macOS), or %AppData% unset (Windows) — e.g. bare Docker containers, cron/systemd jobs, CI runners, or `sudo -i` with a scrubbed environment.

Common situations: Docker images based on scratch/alpine without HOME set; CI jobs running as a service user with no home directory; cron entries lacking the user environment; SSH-ing with `ssh host command` where HOME is not populated.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/a94392eff974a517. Report an issue: GitHub.