{"record":{"id":"07450f67f6b77d25","repo":"mikefarah/yq","slug":"system-command-v-failed-w","errorCode":null,"errorMessage":"system command '%v' failed: %w","messagePattern":"system command '(.+?)' failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_system.go","lineNumber":132,"sourceCode":"\t\tencoded, err := encodeToYamlString(candidate)\n\t\tif err != nil {\n\t\t\treturn Context{}, err\n\t\t}\n\t\tstdin.WriteString(encoded)\n\n\t\t// #nosec G204 - intentional: user must explicitly enable this operator\n\t\tcmd := exec.Command(command, args...)\n\t\tcmd.Stdin = &stdin\n\t\tvar stderr bytes.Buffer\n\t\tcmd.Stderr = &stderr\n\n\t\toutput, err := cmd.Output()\n\t\tif err != nil {\n\t\t\tstderrStr := strings.TrimSpace(stderr.String())\n\t\t\tif stderrStr != \"\" {\n\t\t\t\treturn Context{}, fmt.Errorf(\"system command '%v' failed: %w\\nstderr: %v\", command, err, stderrStr)\n\t\t\t}\n\t\t\treturn Context{}, fmt.Errorf(\"system command '%v' failed: %w\", command, err)\n\t\t}\n\n\t\tresult := string(output)\n\t\tif strings.HasSuffix(result, \"\\r\\n\") {\n\t\t\tresult = result[:len(result)-2]\n\t\t} else if strings.HasSuffix(result, \"\\n\") {\n\t\t\tresult = result[:len(result)-1]\n\t\t}\n\t\tnewNode := candidate.CreateReplacement(ScalarNode, \"!!str\", result)\n\t\tresults.PushBack(newNode)\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n","sourceCodeStart":114,"sourceCodeEnd":147,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_system.go#L114-L147","documentation":"The external command launched by the `system` operator exited with a non-zero status and produced no stderr output, so only the wrapped exec error is reported. This distinguishes failures like 'executable not found' (exec.ErrNotFound / exec.Error) or silent non-zero exits from failures that printed diagnostics.","triggerScenarios":"`system(\"nonexistent-tool\")` where the binary is not on PATH (exec: \"nonexistent-tool\": executable file not found in $PATH), or a command that fails silently with a non-zero exit code and empty stderr.","commonSituations":"Running yq in a container/CI image that lacks the tool installed locally, PATH differences between shell and yq's environment, or tools that signal failure only via exit codes.","solutions":["Verify the executable exists on PATH in the environment yq runs in (which <cmd>); install it or use an absolute path: system(\"/usr/bin/tool\")","If the failure is silent, run the command manually to see its exit code and output","Wrap the command with sh -c to capture/normalize exit status if non-zero exits are expected","Check permissions on the binary (executable bit)"],"exampleFix":"// before: relies on PATH\nsystem(\"kubectl\"; [\"version\"])\n// after: absolute path when PATH differs\nsystem(\"/usr/local/bin/kubectl\"; [\"version\"])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go API usage\nif err != nil && strings.Contains(err.Error(), \"executable file not found\") {\n    // tool missing from PATH: install it or switch to an absolute path\n}","preventionTips":["Verify tool availability (which <cmd>) in the environment running yq, especially containers","Prefer absolute executable paths in system() calls","Check the binary's executable bit and PATH in CI images"],"tags":["yq","system-operator","exec","process-exit","path"],"backgroundTag":"command-not-found","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}