cloudflare/cloudflared · error
error determining stdout path
Error message
error determining stdout path
What it means
Raised by installLaunchd when it cannot determine where launchd should write the tunnel's stdout log file (<home>/Library/Logs/cloudflared.out.log, or /Library/Logs/... for root). The path comes from resolveLibraryPath, so the root cause is typically failure to resolve the user's home directory via homedir.Dir(). The install is aborted so launchd is never given a bogus log path.
Source
Thrown at cmd/cloudflared/macos_service.go:194
// Ensure token file is removed if install fails at any point from now
// on
defer func() {
if err != nil {
removeTokenFile(cp, log)
}
}()
if err = writeTokenToConfigDir(c, cp); err != nil {
return fmt.Errorf("could not write token to configuration directory: %w", err)
}
extraArgs = buildArgsForTokenFile(cp)
}
stdoutPath, err := stdoutPath()
if err != nil {
log.Err(err).Msg("error determining stdout path")
return errors.Wrap(err, "error determining stdout path")
}
stderrPath, err := stderrPath()
if err != nil {
log.Err(err).Msg("error determining stderr path")
return errors.Wrap(err, "error determining stderr path")
}
launchdTemplate := newLaunchdTemplate(installPath, stdoutPath, stderrPath)
templateArgs := ServiceTemplateArgs{Path: etPath, ExtraArgs: extraArgs}
err = launchdTemplate.Generate(&templateArgs)
if err != nil {
log.Err(err).Msg("error generating launchd template")
return err
}
plistPath, err := launchdTemplate.ResolvePath()
if err != nil {
log.Err(err).Msg("error resolving launchd template path")
return err
}View on GitHub (pinned to 2253eeeb25)
Solutions
- Set a valid $HOME (or use `sudo -H`) before running the install.
- Confirm the user's home directory exists and is resolvable via the OS.
- Install as root so /Library/Logs is used and the home-dir lookup is skipped.
- If the underlying cause differs, read the wrapped error printed above this message for the precise OS-level failure.
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "${HOME:-}" ] || [ ! -d "$HOME" ]; then echo "Set a valid HOME before cloudflared service install"; exit 1; fi Try / catch
if err := installCmd.Run(); err != nil && strings.Contains(err.Error(), "stdout path") { log.Warn("home dir unresolved; rerun with sudo -H") } Prevention
- Run installs from a login shell with a resolvable HOME
- Use root install for system-wide LaunchDaemon setup
- Sanity-check `echo $HOME` in CI before installing the service
- Fix Directory Services home records for service accounts
When it happens
Trigger: `cloudflared service install` on macOS when stdoutPath() -> resolveLibraryPath("Logs", ...) -> homedir.Dir() returns an error: $HOME unset or invalid, non-login service account without a home directory, or OS home-dir lookup failure.
Common situations: Installing via sudo without -H so $HOME is stale or missing; running inside containers/CI on macOS runners with no HOME; broken user record in Directory Services.
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
- error determining stderr path
- Error determining install path
- error determining install path
- error determining executable path: %w
- could not write token to configuration directory: %w
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/fcca00d9d06408b3.
Report an issue: GitHub.