{"record":{"id":"a99c5f335a495736","repo":"mikefarah/yq","slug":"aborted","errorCode":null,"errorMessage":"aborted","messagePattern":"aborted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_error.go","lineNumber":19,"sourceCode":"package yqlib\n\nimport (\n\t\"errors\"\n)\n\nfunc errorOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\n\tlog.Debugf(\"errorOperation\")\n\n\trhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)\n\tif err != nil {\n\t\treturn Context{}, err\n\t}\n\terrorMessage := \"aborted\"\n\tif rhs.MatchingNodes.Len() > 0 {\n\t\terrorMessage = rhs.MatchingNodes.Front().Value.(*CandidateNode).Value\n\t}\n\treturn Context{}, errors.New(errorMessage)\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_error.go#L1-L21","documentation":"This is not an internal fault: yq's `error` operator deliberately aborts expression evaluation and returns an error whose message is the operator's RHS value (defaulting to \"aborted\" when the RHS produces no nodes). It is yq's equivalent of `error`/`throw` in other languages, so any expression like `... || error(\"msg\")` surfaces this error when the guard condition fails.","triggerScenarios":"An expression using the `error` operator executes, e.g. `.foo == null and error(\"foo is missing\")` or `.x // error`, and either the RHS evaluates to a node whose Value becomes the message, or the RHS is empty (message defaults to \"aborted\").","commonSituations":"Validation-style yq pipelines in CI that intentionally fail when data is missing or invalid; copying examples with `// error(\"...\")` where the left side unexpectedly yields null; running `error` with no argument and wondering why the message is just 'aborted'.","solutions":["Read the error message as data from your expression — fix the underlying condition that made the guard fire (e.g. the missing key or null value).","If 'aborted' appears with no detail, add an explicit message: replace bare `error` with `error(\"descriptive message\")`.","If the abort is unintended, restructure the expression (e.g. use `// .fallback` instead of `// error(...)`) so the failing path is not taken.","Catch the error at the process level (non-zero exit code) and handle it in the surrounding script if it is an expected validation failure."],"exampleFix":"// before: unhelpful message when value missing\n./yq '.value // error' file.yaml\n// error: aborted\n// after: provide a clear message and a default path\n./yq '.value // error(\".value is required\")' file.yaml","handlingStrategy":"try-catch","validationCode":"// Pre-check the guard condition so error() never fires unexpectedly:\nyq '.value != null' file.yaml || echo \"value missing\"","typeGuard":"// Go: detect an error-operator abort by message\nclassifier := func(err error) bool {\n    return err != nil && (err.Error() == \"aborted\" || strings.HasPrefix(err.Error(), \"error op\"))\n}","tryCatchPattern":"// Go API\nout, err := navigator.GetMatchingNodes(ctx, expr)\nif err != nil {\n    if err.Error() == \"aborted\" || isMyValidationMessage(err) {\n        // handle expected validation abort\n        return handleAbort(err)\n    }\n    return err\n}","preventionTips":["Always pass an explicit message to error() so failures are diagnosable","Use error() only in intentional validation guards, not general plumbing","Treat yq's non-zero exit as data-driven failure in shell scripts (`|| handle`)"],"tags":["go","yq","expression","control-flow"],"backgroundTag":"expression-aborted","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"}