{"record":{"id":"43a96c5fa79109ea","repo":"mikefarah/yq","slug":"bad-expression-probably-missing-close-bracket-on","errorCode":null,"errorMessage":"bad expression - probably missing close bracket on %v","messagePattern":"bad expression - probably missing close bracket on (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/expression_postfix.go","lineNumber":133,"sourceCode":"\t\t\tfor len(opStack) > 0 &&\n\t\t\t\topStack[len(opStack)-1].TokenType == operationToken &&\n\t\t\t\topStack[len(opStack)-1].Operation.OperationType.Precedence > currentPrecedence {\n\t\t\t\topStack, result = popOpToResult(opStack, result)\n\t\t\t}\n\t\t\t// add this operator to the opStack\n\t\t\topStack = append(opStack, currentToken)\n\t\t\tlog.Debugf(\"put %v onto the opstack\", currentToken.toString(true))\n\t\t}\n\t}\n\n\tlog.Debugf(\"opstackLen: %v\", len(opStack))\n\tif len(opStack) > 0 {\n\t\tlog.Debugf(\"opstack:\")\n\t\tfor _, token := range opStack {\n\t\t\tlog.Debugf(\"- %v\", token.toString(true))\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"bad expression - probably missing close bracket on %v\", opStack[len(opStack)-1].toString(false))\n\t}\n\n\tif log.IsEnabledFor(slog.LevelDebug) {\n\t\tlog.Debugf(\"PostFix Result:\")\n\t\tfor _, currentToken := range result {\n\t\t\tlog.Debugf(\"> %v\", currentToken.toString())\n\t\t}\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":115,"sourceCodeEnd":145,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/expression_postfix.go#L115-L145","documentation":"ConvertToPostfix ends with a non-empty operator stack, meaning an operator or open token never got reduced by a closer. The error names the last remaining token ('probably missing close bracket on %v') to point at the offending construct.","triggerScenarios":"Expressions with an unbalanced structural token that slips past specific checks, e.g. `yq '.[]'` variants with missing closers in complex nesting like `yq '.a[.b(' — the leftover token is reported in the message.","commonSituations":"Deeply nested collect/select expressions in automation scripts, expressions built by string concatenation where a closer was conditional and skipped.","solutions":["Read the reported token in the message and add its matching closer","Rewrite the expression more simply / split with pipes to reduce nesting","Validate bracket balance programmatically before invoking yq in scripts"],"exampleFix":"// before\nyq '.a[.b(select(.c' file.yml\n// after\nyq '.a[.b(select(.c))]' file.yml","handlingStrategy":"validation","validationCode":"for _, pair := range [][2]string{\"[]\", \"{}\", \"()\"} {\n    if strings.Count(expr, pair[:1]) != strings.Count(expr, pair[1:]) {\n        return fmt.Errorf(\"unbalanced %s in %q\", pair, expr)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := runYq(expr, file)\nif err != nil && strings.Contains(err.Error(), \"probably missing close bracket\") {\n    // the message names the leftover token; surface it to the user\n    return fmt.Errorf(\"unbalanced expression %q: %w\", expr, err)\n}","preventionTips":["Build nested expressions incrementally, closing brackets as you go","Prefer piping simpler stages (`|`) over deep bracket nesting","Unit-test any code that generates yq expressions"],"tags":["expression","bracket","syntax"],"backgroundTag":"unclosed-bracket-expression","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"}