{"record":{"id":"f7b7cad0874a27c0","repo":"cloudflare/cloudflared","slug":"s-v-returned-with-error-code-v-due-to-v","errorCode":null,"errorMessage":"%s %v returned with error code %v due to: %v","messagePattern":"(.+?) (.+?) returned with error code (.+?) due to: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/service_template.go","lineNumber":106,"sourceCode":"\t\tservice,\n\t)\n}\n\nfunc runCommand(command string, args ...string) error {\n\tcmd := exec.Command(command, args...)\n\tstderr, err := cmd.StderrPipe()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting stderr pipe: %v\", err)\n\t}\n\terr = cmd.Start()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error starting %s: %v\", command, err)\n\t}\n\n\toutput, _ := io.ReadAll(stderr)\n\terr = cmd.Wait()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s %v returned with error code %v due to: %v\", command, args, err, string(output))\n\t}\n\treturn nil\n}\n","sourceCodeStart":88,"sourceCodeEnd":110,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/service_template.go#L88-L110","documentation":"The service command executed but exited non-zero; runCommand returns the command, its args, exit code, and captured stderr. This is the standard failure mode when installing/uninstalling the cloudflared service via systemctl/service/rc-service.","triggerScenarios":"systemctl refuses to enable the unit (root required), the service file is invalid, the config token is bad, rc-service/service scripts reject the operation, or a name conflict exists (service already installed/uninstalled).","commonSituations":"Running 'cloudflared service install' without sudo; installing with an already-used service name; malformed /etc/systemd/system/cloudflared.service; SELinux or permission issues on the unit file.","solutions":["Run the command with root privileges (sudo cloudflared service install)","Read the 'due to:' portion of the message — it contains the actual stderr from systemctl/service/rc-service","Fix the reported unit/config problem (validate the service file, remove a stale unit, systemctl daemon-reload)","Check logs: journalctl -u cloudflared for systemd systems"],"exampleFix":"# before\ncloudflared service install <token>\n# after\nsudo cloudflared service install <token>","handlingStrategy":"try-catch","validationCode":"if os.Geteuid() != 0 {\n\treturn errors.New(\"installing the service requires root; rerun with sudo\")\n}","typeGuard":null,"tryCatchPattern":"if err := runCommand(\"systemctl\", \"enable\", \"--now\", serviceFile); err != nil {\n\t// err already embeds stderr output ('due to: ...')\n\tvar exitErr *exec.ExitError\n\tif errors.As(err, &exitErr) {\n\t\tlog.Debug().Int(\"code\", exitErr.ExitCode()).Msg(\"service command exit\")\n\t}\n\treturn err\n}","preventionTips":["Run service install/uninstall with sudo/root","Read the stderr appended to the error message first","Run `systemctl daemon-reload` after replacing unit files","Check for an existing cloudflared service before installing"],"tags":["go","exec","service-management","exit-code"],"backgroundTag":"git-command-failed","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"}