{"record":{"id":"4c896ee9cd49b9e6","repo":"cloudflare/cloudflared","slug":"error-determining-executable-path-w","errorCode":null,"errorMessage":"error determining executable path: %w","messagePattern":"error determining executable path: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/macos_service.go","lineNumber":150,"sourceCode":"\treturn resolveLibraryPath(\"Application Support\", launchdIdentifier)\n}\n\nfunc installLaunchd(c *cli.Context) error {\n\tlog := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)\n\n\tif isRootUser() {\n\t\tlog.Info().Msg(\"Installing cloudflared client as a system launch daemon. \" +\n\t\t\t\"cloudflared client will run at boot\")\n\t} else {\n\t\tlog.Info().Msg(\"Installing cloudflared client as an user launch agent. \" +\n\t\t\t\"Note that cloudflared client will only run when the user is logged in. \" +\n\t\t\t\"If you want to run cloudflared client at boot, install with root permission. \" +\n\t\t\t\"For more information, visit https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/configure-tunnels/local-management/as-a-service/macos/\")\n\t}\n\tetPath, err := os.Executable()\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"Error determining executable path\")\n\t\treturn fmt.Errorf(\"error determining executable path: %w\", err)\n\t}\n\tinstallPath, err := installPath()\n\tif err != nil {\n\t\tlog.Err(err).Msg(\"Error determining install path\")\n\t\treturn errors.Wrap(err, \"Error determining install path\")\n\t}\n\n\tvar extraArgs []string\n\tif c.NArg() > 0 {\n\t\t// The service has been installed using a token e.g.,\n\t\t// $ cloudflared service install <token>\n\t\t//\n\t\t// Write the token file to a config directory so we can start the\n\t\t// daemon with --token-file\n\n\t\t// Don't use :=, if we did so we would create a new err variable and\n\t\t// shadow the outer one, causing the defer below to not have access to\n\t\t// the outer err","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/macos_service.go#L132-L168","documentation":"installLaunchd on macOS wraps os.Executable() failures with \"error determining executable path: %w\" when installing cloudflared as a launchd service. os.Executable() fails when the OS cannot report the path of the running binary (e.g. the binary was deleted or renamed after start). The plist written for launchd needs this path to point at the correct executable, so install aborts.","triggerScenarios":"Running `cloudflared service install` (macOS) when os.Executable() returns an error: the running binary was deleted or moved after process start, the binary is running from a deleted temp/download directory, or on exotic setups (e.g. overwriting the binary in place during an upgrade) where the OS lookup (proc_pidpath / sysctl) fails.","commonSituations":"Users who download cloudflared to ~/Downloads, run `sudo ./cloudflared service install`, then their cleanup tool deletes the download; installing from a binary inside a removed tmp dir; upgrade scripts that replace the file between process start and install.","solutions":["Copy the cloudflared binary to a stable location (e.g. /usr/local/bin/cloudflared or /opt/homebrew/bin) and run the install from there","Do not delete, move, or overwrite the binary while the install command is running","Re-download/reinstall the binary if it is corrupted or missing, then retry the install","Check the wrapped error (%w) in the log output for the underlying OS reason and address it specifically"],"exampleFix":"// before (fragile)\ncd ~/Downloads && sudo ./cloudflared service install\nrm ~/Downloads/cloudflared  # binary gone after start => error\n\n// after\nsudo cp ~/Downloads/cloudflared /usr/local/bin/cloudflared\nsudo /usr/local/bin/cloudflared service install","handlingStrategy":"try-catch","validationCode":"// Go: verify the binary location is stable before installing\nif _, err := os.Stat(os.Args[0]); err != nil {\n    return fmt.Errorf(\"binary no longer at start path; copy to a stable location first: %w\", err)\n}","typeGuard":"func executableOK() bool { p, err := os.Executable(); return err == nil && p != \"\" }","tryCatchPattern":"if err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        log.Printf(\"binary missing at %s; reinstall to a stable path\", pe.Path)\n    }\n    return fmt.Errorf(\"error determining executable path: %w\", err)\n}","preventionTips":["Always install cloudflared from a permanent location like /usr/local/bin, never from ~/Downloads or /tmp","Never delete or overwrite the binary while a service install is running","Automate installs to copy the binary first, then run `service install` from the final path"],"tags":["macos","launchd","service-install","filesystem"],"backgroundTag":"file-not-found","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"}