{"record":{"id":"7bb2403ef96ca7fc","repo":"fatedier/frp","slug":"failed-to-execute-command-v-v","errorCode":null,"errorMessage":"failed to execute command %v: %v","messagePattern":"failed to execute command (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/v1/value_source.go","lineNumber":153,"sourceCode":"}\n\n// Resolve reads and returns the content captured from stdout of launched subprocess.\nfunc (e *ExecSource) Resolve(ctx context.Context) (string, error) {\n\tif err := e.Validate(); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tcmd := exec.CommandContext(ctx, e.Command, e.Args...)\n\tif len(e.Env) != 0 {\n\t\tcmd.Env = os.Environ()\n\t\tfor _, env := range e.Env {\n\t\t\tcmd.Env = append(cmd.Env, env.Name+\"=\"+env.Value)\n\t\t}\n\t}\n\n\tcontent, err := cmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to execute command %v: %v\", e.Command, err)\n\t}\n\n\t// Trim whitespace, which is important for exec-based tokens\n\treturn strings.TrimSpace(string(content)), nil\n}\n","sourceCodeStart":135,"sourceCodeEnd":159,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/v1/value_source.go#L135-L159","documentation":"ExecSource.Resolve() wraps the exec.Cmd.Output() failure for the configured command. The wrapped error is usually an *exec.ExitError (non-zero exit or signal kill), a \"command not found\" path error, or a context-deadline error if ctx was cancelled. Only stdout is captured; anything the command writes to stderr is discarded by Output().","triggerScenarios":"ValueSource{Type: \"exec\"}.Resolve(ctx) where the command exits non-zero, does not exist in PATH, is not executable, is killed by the context deadline, or cannot run due to missing runtime (e.g. no shell, missing interpreter).","commonSituations":"Token-fetch helper (aws sts get-session-token, vault print token) fails because of expired credentials or no network; command installed on the admin's laptop but not in the frpc container image; context deadline too short for a cloud API call; script not marked executable or uses a shebang for a missing interpreter.","solutions":["Run the exact command manually as the frp service user to see the real failure: sudo -u frp <command> <args...>.","Ensure the binary/script exists in the container/image and PATH; use an absolute path for command.","If the command is slow, pass a context with a longer deadline to Resolve().","Check exit status in the returned error (*exec.ExitError) — stderr output is not included in this error message.","For scripts, verify the executable bit and shebang."],"exampleFix":"# before\n[auth.token.valueSource]\ntype = \"exec\"\nexec.command = \"get-token\"   # not in PATH inside container\n\n# after\nexec.command = \"/usr/local/bin/get-token\"\n# or inline shell:\nexec.command = \"sh\"\nexec.args = [\"-c\", \"cat /run/secrets/token\"]","handlingStrategy":"try-catch","validationCode":"func execResolves(command string, args []string) error {\n\tif command == \"\" {\n\t\treturn errors.New(\"empty command\")\n\t}\n\tpath, err := exec.LookPath(command)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"command %q not found in PATH: %w\", command, err)\n\t}\n\t_ = path\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"val, err := vs.Resolve(ctx)\nif err != nil {\n\tvar exitErr *exec.ExitError\n\tif errors.As(err, &exitErr) {\n\t\t// command ran but failed: capture stderr yourself by running it out-of-band; fix credentials/env\n\t\tlog.Printf(\"helper exited %d\", exitErr.ExitCode())\n\t} else if ctx.Err() != nil {\n\t\t// deadline: lengthen the context timeout\n\t}\n\treturn err\n}","preventionTips":["Test the helper command manually as the frp service user before enabling it.","Prefer absolute paths for command; ensure the binary ships in the container image.","Give Resolve a context deadline sized for the helper (cloud IAM calls can take seconds).","Remember stderr is discarded — make the helper report failures via exit code."],"tags":["exec","subprocess","config","frp","shell"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}