{"record":{"id":"78cd36dedb2ec783","repo":"sqshq/sampler","slug":"failed-to-execute-command-s-78cd36","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_pty.go","lineNumber":78,"sourceCode":"\t\t\treturn err\n\t\t}\n\t\ttime.Sleep(startupTimeout) // TODO wait until cmd complete\n\t}\n\n\treturn nil\n}\n\nfunc (s *PtyInteractiveShell) execute() (string, error) {\n\n\t_, err := io.WriteString(s.file, 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\t_ = s.file.Close()\n\t\t\ts.item.ptyShell = nil // restart session\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"failed to execute command: %s\", err)\n\t}\n\n\tsoftTimeout := make(chan bool, 1)\n\thardTimeout := make(chan bool, 1)\n\n\tgo func() {\n\t\ttime.Sleep(s.getAwaitTimeout() / 2)\n\t\tsoftTimeout <- true\n\t\ttime.Sleep(s.getAwaitTimeout() * 100)\n\t\thardTimeout <- true\n\t}()\n\n\tvar builder strings.Builder\n\tsoftTimeoutElapsed := false\n\nawait:\n\tfor {\n\t\tselect {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/sqshq/sampler/blob/9bc7ba732d31f32a917ad4b5605f00b76ebe0891/data/int_pty.go#L60-L96","documentation":"The PTY interactive shell wraps errors from starting the command on the pseudo-terminal into \"failed to execute command: <underlying error>\". On repeated failures past errorThreshold it closes the PTY file and nils item.ptyShell to restart the session cleanly. The actionable information is the wrapped underlying error.","triggerScenarios":"cmd.Start (or PTY setup) failing while executing a command through PtyInteractiveShell — missing executable, invalid args, PTY open failure — or accumulated session errors exceeding errorThreshold.","commonSituations":"Same class as basic: command not found in the service's PATH, script permissions, PTY resource exhaustion on the host, binary incompatible with the OS.","solutions":["Inspect the wrapped underlying error after the colon and address it directly","Use absolute executable paths and ensure execute permissions","Confirm PTY support on the host (enough ptys available; not a restricted container without /dev/ptmx)","Let the session restart logic work: after errorThreshold the library rebuilds the shell; fix the root cause so retries succeed","On Windows switch to the basic shell since PTY is not supported there"],"exampleFix":"// before\nscript: pty-runner\n// after\nscript: /usr/local/bin/pty-runner  # exists, +x, PATH-independent","handlingStrategy":"try-catch","validationCode":"path, err := exec.LookPath(cmdName); if err != nil || runtime.GOOS == \"windows\" { fall back to basic shell }","typeGuard":null,"tryCatchPattern":"out, err := ptyShell.execute()\nif err != nil {\n    log.Printf(\"PTY exec failed: %v\", err) // root cause is wrapped after the colon\n    // session auto-restarts after errorThreshold; monitor repeated occurrences\n}","preventionTips":["Prefer absolute paths and +x permissions for PTY-run scripts","Check /dev/ptmx availability in containers","Don't run PTY items on Windows"],"tags":["go","exec","pty","command-failed"],"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"}