{"record":{"id":"9ac15d9f69a2d9a0","repo":"mikefarah/yq","slug":"system-operator-command-expression-returned-no-re","errorCode":null,"errorMessage":"system operator: command expression returned no results","messagePattern":"system operator: command expression returned no results","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_system.go","lineNumber":46,"sourceCode":"\t\tif len(args) == 0 {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn args, nil\n\t}\n\n\t// Single-argument case: only accept a non-null scalar node.\n\tif argsNode.Tag == \"!!null\" {\n\t\treturn nil, nil\n\t}\n\tif argsNode.Kind != ScalarNode {\n\t\treturn nil, fmt.Errorf(\"system operator: args must be a non-null scalar or sequence of non-null scalars; got kind=%v tag=%v\", argsNode.Kind, argsNode.Tag)\n\t}\n\treturn []string{argsNode.Value}, nil\n}\n\nfunc resolveCommandNode(commandNodes Context) (string, error) {\n\tif commandNodes.MatchingNodes.Front() == nil {\n\t\treturn \"\", fmt.Errorf(\"system operator: command expression returned no results\")\n\t}\n\tif commandNodes.MatchingNodes.Len() > 1 {\n\t\tlog.Debugf(\"system operator: command expression returned %d results, using first\", commandNodes.MatchingNodes.Len())\n\t}\n\tcmdNode := commandNodes.MatchingNodes.Front().Value.(*CandidateNode)\n\tif cmdNode.Kind != ScalarNode || cmdNode.guessTagFromCustomType() != \"!!str\" {\n\t\treturn \"\", fmt.Errorf(\"system operator: command must be a string scalar\")\n\t}\n\tif cmdNode.Value == \"\" {\n\t\treturn \"\", fmt.Errorf(\"system operator: command must be a non-empty string\")\n\t}\n\treturn cmdNode.Value, nil\n}\n\nfunc systemOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tif !ConfiguredSecurityPreferences.EnableSystemOps {\n\t\treturn Context{}, fmt.Errorf(\"system operations are disabled, use --security-enable-system-operator to enable\")\n\t}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_system.go#L28-L64","documentation":"The `system` operator requires a command string from its RHS expression, but the expression matched zero nodes. resolveCommandNode throws this when the command expression yields an empty result set, so there is nothing to execute.","triggerScenarios":"`system(.missingCommandField)` where the key does not exist on the current node (e.g. `.cmd` absent from the YAML), or a command expression filtered to nothing like `system(.cmds[] | select(.enabled))` matching no entries.","commonSituations":"Typo in the field name holding the command, running the expression against documents that lack the command key, or a select() filter that eliminates all candidates.","solutions":["Verify the field name in the command expression exists in the input documents","Provide a fallback default: `system(.cmd // \"echo\")` or use alternative// to supply a literal","Check the input data — run just the command expression alone (e.g. `yq '.cmd' file.yml`) to confirm it returns a value"],"exampleFix":"// before: .cmd may be missing\nsystem(.cmd)\n// after: default when missing\nsystem(.cmd // \"echo\")","handlingStrategy":"fallback","validationCode":"// default the command expression\nsystem(.cmd // \"echo\")","typeGuard":null,"tryCatchPattern":"// Go API usage\nresult, err := yqEval(expr, doc)\nif err != nil && strings.Contains(err.Error(), \"command expression returned no results\") {\n    // handle missing command field: use default or skip\n}","preventionTips":["Supply a default with // in the command expression","Verify the field exists in all input documents before piping into system()","Run the command expression standalone to confirm it matches nodes"],"tags":["yq","system-operator","empty-result","expression"],"backgroundTag":"empty-expression-result","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"}