{"record":{"id":"3dccb0d59b8baaa6","repo":"cloudflare/cloudflared","slug":"error-retrieving-output-from-command-s-w-3dccb0","errorCode":null,"errorMessage":"error retrieving output from command '%s': %w","messagePattern":"error retrieving output from command '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diagnostic/system_collector_macos.go","lineNumber":115,"sourceCode":"\n\treturn info, err\n}\n\nfunc collectFileDescriptorInformation(ctx context.Context) (\n\t*FileDescriptorInformation,\n\tstring,\n\terror,\n) {\n\tconst (\n\t\tfileDescriptorMaximumKey = \"kern.maxfiles\"\n\t\tfileDescriptorCurrentKey = \"kern.num_files\"\n\t)\n\n\tcommand := exec.CommandContext(ctx, \"sysctl\", fileDescriptorMaximumKey, fileDescriptorCurrentKey)\n\n\tstdout, err := command.Output()\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"error retrieving output from command '%s': %w\", command.String(), err)\n\t}\n\n\toutput := string(stdout)\n\n\tfileDescriptorInfo, err := ParseFileDescriptorInformationFromKV(\n\t\toutput,\n\t\tfileDescriptorMaximumKey,\n\t\tfileDescriptorCurrentKey,\n\t)\n\tif err != nil {\n\t\treturn nil, output, err\n\t}\n\n\t// returning raw output in case other collected information\n\t// resulted in errors\n\treturn fileDescriptorInfo, output, nil\n}\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/diagnostic/system_collector_macos.go#L97-L133","documentation":"This error wraps a failure of `exec.CommandContext(ctx, \"sysctl\", ...).Output()` when collecting file descriptor limits on macOS. The library runs `sysctl kern.maxfiles kern.maxfilesperproc` and expects a zero exit code; if sysctl is missing, errors, or is killed (e.g. by context cancellation), the raw error is wrapped with the full command string via `%w` so callers can unwrap with errors.As/Is.","triggerScenarios":"Calling Collect() on a macOS host when: the `sysctl` binary is not on PATH; kern.maxfiles / kern.maxfilesperproc are unavailable on the kernel; the passed context is cancelled before Output() returns; or the child process exits non-zero for any reason.","commonSituations":"Running in a sandboxed/limited container that stubs or removes sysctl, minimal macOS environments (e.g. CI images) with stripped-down /usr/sbin PATH, or diagnostic collection invoked with a short-lived context that times out while the command runs.","solutions":["Verify `sysctl kern.maxfiles kern.maxfilesperproc` succeeds in a shell on the affected host; fix PATH or restore the binary if it fails.","Check the wrapped error (`errors.Unwrap` / `%w` chain) — exec.ExitError means sysctl ran and failed, exec.ErrNotFound means it was not found on PATH.","Ensure the context passed to Collect has enough budget for the sysctl call; increase the timeout if context.DeadlineExceeded is the cause.","If the host is not macOS or lacks these sysctls, skip macOS-specific collection or run the collector on a supported platform."],"exampleFix":"// before\nstdout, err := command.Output()\nif err != nil {\n\treturn nil, \"\", fmt.Errorf(\"error retrieving output from command '%s': %w\", command.String(), err)\n}\n// after\nstdout, err := command.Output()\nvar exitErr *exec.ExitError\nif errors.As(err, &exitErr) {\n\treturn nil, \"\", fmt.Errorf(\"error retrieving output from command '%s': %w, stderr: %s\", command.String(), err, exitErr.Stderr)\n}\nif err != nil {\n\treturn nil, \"\", fmt.Errorf(\"error retrieving output from command '%s': %w\", command.String(), err)\n}","handlingStrategy":"try-catch","validationCode":"if runtime.GOOS != \"darwin\" {\n\treturn fmt.Errorf(\"file descriptor collection is macOS-only\")\n}\nif _, err := exec.LookPath(\"sysctl\"); err != nil {\n\treturn fmt.Errorf(\"sysctl not available: %w\", err)\n}\nif err := ctx.Err(); err != nil {\n\treturn fmt.Errorf(\"context already cancelled: %w\", err)\n}","typeGuard":"var exitErr *exec.ExitError\nif errors.As(err, &exitErr) { /* sysctl ran and failed; inspect exitErr.Stderr */ }","tryCatchPattern":"info, extra, err := collector.Collect(ctx)\nif err != nil {\n\tif errors.Is(err, exec.ErrNotFound) {\n\t\tlog.Warn().Msg(\"sysctl missing; skipping fd diagnostics\")\n\t} else if errors.Is(err, context.DeadlineExceeded) {\n\t\tlog.Warn().Msg(\"fd diagnostics timed out\")\n\t} else {\n\t\treturn fmt.Errorf(\"fd diagnostics failed: %w\", err)\n\t}\n}","preventionTips":["Check exec.LookPath(\"sysctl\") before enabling macOS diagnostics.","Give the collection context a generous timeout.","Unwrap the error to distinguish not-found vs exit-failure vs cancellation.","Test collectors on minimal/sandboxed macOS images where sysctl may be absent."],"tags":["macos","exec","diagnostics","command-execution"],"backgroundTag":"command-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"}