{"record":{"id":"53fcc0acabe7df82","repo":"cloudflare/cloudflared","slug":"error-determining-stderr-path","errorCode":null,"errorMessage":"error determining stderr path","messagePattern":"error determining stderr path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/macos_service.go","lineNumber":199,"sourceCode":"\t\t\t}\n\t\t}()\n\n\t\tif err = writeTokenToConfigDir(c, cp); err != nil {\n\t\t\treturn fmt.Errorf(\"could not write token to configuration directory: %w\", err)\n\t\t}\n\n\t\textraArgs = buildArgsForTokenFile(cp)\n\t}\n\n\tstdoutPath, err := stdoutPath()\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"error determining stdout path\")\n\t\treturn errors.Wrap(err, \"error determining stdout path\")\n\t}\n\tstderrPath, err := stderrPath()\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"error determining stderr path\")\n\t\treturn errors.Wrap(err, \"error determining stderr path\")\n\t}\n\tlaunchdTemplate := newLaunchdTemplate(installPath, stdoutPath, stderrPath)\n\ttemplateArgs := ServiceTemplateArgs{Path: etPath, ExtraArgs: extraArgs}\n\terr = launchdTemplate.Generate(&templateArgs)\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"error generating launchd template\")\n\t\treturn err\n\t}\n\tplistPath, err := launchdTemplate.ResolvePath()\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"error resolving launchd template path\")\n\t\treturn err\n\t}\n\n\tlog.Info().Msgf(\"Outputs are logged to %s and %s\", stderrPath, stdoutPath)\n\terr = runCommand(\"launchctl\", \"load\", plistPath)\n\tif err == nil {\n\t\tlog.Info().Msg(\"MacOS service for cloudflared installed successfully\")","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/macos_service.go#L181-L217","documentation":"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.","triggerScenarios":"`cloudflared service install` on macOS when stderrPath() -> homedir.Dir() fails: $HOME missing/invalid, user without a home directory, or OS-level home lookup error.","commonSituations":"sudo without -H in scripts; headless macOS automation with unset HOME; damaged user account records.","solutions":["Export a valid HOME or run with `sudo -H cloudflared service install`.","Verify the executing user's home directory via `dscl` and fix it if missing.","Run the install as root (uses /Library/Logs, no homedir lookup).","Inspect the underlying error logged by zerolog for the exact OS failure."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"[ -n \"$HOME\" ] && [ -d \"$HOME\" ] || { echo \"invalid HOME\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"stderr path\") { rerunWithValidHome() }","preventionTips":["Prefer `sudo -H cloudflared service install` in scripts","Confirm Logs directory location assumptions match root vs user install","Avoid stripped cron/CI environments for interactive service setup","Audit user home directories after account migrations"],"tags":["macos","launchd","logging","home-directory"],"backgroundTag":"missing-env-var","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}