{"record":{"id":"fcca00d9d06408b3","repo":"cloudflare/cloudflared","slug":"error-determining-stdout-path","errorCode":null,"errorMessage":"error determining stdout path","messagePattern":"error determining stdout path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/macos_service.go","lineNumber":194,"sourceCode":"\t\t// Ensure token file is removed if install fails at any point from now\n\t\t// on\n\t\tdefer func() {\n\t\t\tif err != nil {\n\t\t\t\tremoveTokenFile(cp, log)\n\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}","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/macos_service.go#L176-L212","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if [ -z \"${HOME:-}\" ] || [ ! -d \"$HOME\" ]; then echo \"Set a valid HOME before cloudflared service install\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"if err := installCmd.Run(); err != nil && strings.Contains(err.Error(), \"stdout path\") { log.Warn(\"home dir unresolved; rerun with sudo -H\") }","preventionTips":["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"],"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"}