cloudflare/cloudflared · error

error determining stderr path

Error message

error determining stderr path

What it means

Raised by installLaunchd when it cannot determine the launchd stderr log path (<home>/Library/Logs/cloudflared.err.log or /Library/Logs/... for root). Like the stdout variant, stderrPath() delegates to resolveLibraryPath, whose only failure mode is the homedir.Dir() lookup, so the wrapped error is a home-directory resolution failure. Install aborts before writing the plist.

Source

Thrown at cmd/cloudflared/macos_service.go:199

			}
		}()

		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
	}

	log.Info().Msgf("Outputs are logged to %s and %s", stderrPath, stdoutPath)
	err = runCommand("launchctl", "load", plistPath)
	if err == nil {
		log.Info().Msg("MacOS service for cloudflared installed successfully")

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Export a valid HOME or run with `sudo -H cloudflared service install`.
  2. Verify the executing user's home directory via `dscl` and fix it if missing.
  3. Run the install as root (uses /Library/Logs, no homedir lookup).
  4. Inspect the underlying error logged by zerolog for the exact OS failure.
Defensive patterns

Strategy: validation

Validate before calling

[ -n "$HOME" ] && [ -d "$HOME" ] || { echo "invalid HOME"; exit 1; }

Try / catch

if err != nil && strings.Contains(err.Error(), "stderr path") { rerunWithValidHome() }

Prevention

When it happens

Trigger: `cloudflared service install` on macOS when stderrPath() -> homedir.Dir() fails: $HOME missing/invalid, user without a home directory, or OS-level home lookup error.

Common situations: sudo without -H in scripts; headless macOS automation with unset HOME; damaged user account records.

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 cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/53fcc0acabe7df82. Report an issue: GitHub.