{"record":{"id":"4ec8ce75593387bd","repo":"sqshq/sampler","slug":"failed-to-execute-command-s","errorCode":null,"errorMessage":"failed to execute command: %s","messagePattern":"failed to execute command: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"data/int_basic.go","lineNumber":93,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc (s *BasicInteractiveShell) execute() (string, error) {\n\n\tif s.stdin == nil {\n\t\treturn \"\", nil\n\t}\n\n\t_, err := io.WriteString(s.stdin, fmt.Sprintf(\" %s\\n\", s.item.sampleScript))\n\tif err != nil {\n\t\ts.errCount++\n\t\tif s.errCount > errorThreshold {\n\t\t\t_ = s.cmd.Wait()\n\t\t\ts.item.basicShell = nil // restart session\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"failed to execute command: %s\", err)\n\t}\n\n\ttimeout := make(chan bool, 1)\n\n\tgo func() {\n\t\ttime.Sleep(s.timeout)\n\t\ttimeout <- true\n\t}()\n\n\tvar resultText strings.Builder\n\tvar errorText strings.Builder\n\n\tfor {\n\t\tselect {\n\t\tcase stdout := <-s.stdoutCh:\n\t\t\tif len(stdout) > 0 {\n\t\t\t\tresultText.WriteString(stdout)\n\t\t\t\tresultText.WriteString(\"\\n\")","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/sqshq/sampler/blob/9bc7ba732d31f32a917ad4b5605f00b76ebe0891/data/int_basic.go#L75-L111","documentation":"The basic interactive shell wraps any error from starting or communicating with the underlying command (cmd.Start / related exec calls) into \"failed to execute command: <underlying error>\". After repeated failures beyond errorThreshold, the library also drops the cached shell (item.basicShell = nil) so a fresh session is started next time. The root cause is always in the wrapped err string.","triggerScenarios":"cmd.Start fails when running a command through the basic interactive shell — e.g. executable not on PATH, bad working directory, missing binary permissions — or repeated session errors tripping errorThreshold and forcing a session restart.","commonSituations":"Typo'd or missing command name in the item config; command present interactively but not in the collector's PATH (cron/systemd environments); script without execute bit; cwd removed.","solutions":["Read the wrapped underlying error (after the colon) and fix that cause first (PATH, binary name, permissions)","Use an absolute path to the executable in the item configuration","Verify the command runs under the same user/environment the collector runs as (echo $PATH)","Check the working directory and file permissions if the error mentions chdir or permission denied"],"exampleFix":"// before\nscript: myscript.sh\n// after\nscript: /opt/scripts/myscript.sh  # absolute path, chmod +x applied","handlingStrategy":"try-catch","validationCode":"path, err := exec.LookPath(cmdName)\nif err != nil { return fmt.Errorf(\"command %q not found in PATH\", cmdName) }","typeGuard":null,"tryCatchPattern":"out, err := shell.execute()\nvar execErr *exec.Error\nif err != nil {\n    if errors.As(err, &execErr) {\n        log.Fatalf(\"fix PATH or binary name: %v\", execErr)\n    }\n    return err\n}","preventionTips":["Use absolute executable paths in item configs","Verify the collector's runtime user/environment can see the binary","Smoke-test commands with the exact service account"],"tags":["go","exec","command-failed","interactive-shell"],"backgroundTag":"command-not-found","analyzedSha":"9bc7ba732d31f32a917ad4b5605f00b76ebe0891","analyzedAt":"2026-09-06T08:38:02.595Z","contentChangedAt":"2026-09-06T08:38:02.595Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}