{"record":{"id":"cefe25b5d9f4a090","repo":"SigNoz/signoz","slug":"errcodeinvalidscopeexpression","errorCode":"ErrCodeInvalidScopeExpression","errorMessage":"compile scope expression %q","messagePattern":"compile scope expression %q","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"pkg/types/alertmanagertypes/expression.go","lineNumber":77,"sourceCode":"\t\t// (nested wins) and flag.\n\t\tif _, isMap := env[key].(map[string]any); isMap {\n\t\t\tconflict = true\n\t\t\tcontinue\n\t\t}\n\t\tenv[key] = value\n\t}\n\treturn env, conflict\n}\n\n// EvalScopeExpression compiles and runs the expression against the provided\n// labels. It returns (result, error). Callers should log the error and\n// decide how to handle a failed evaluation (the maintenance muter treats a\n// failure as \"don't skip\" so alerts pass through).\nfunc EvalScopeExpression(expression string, lset model.LabelSet) (bool, error) {\n\tenv, _ := ConvertLabelSetToEnv(lset)\n\tprogram, err := expr.Compile(expression, expr.Env(env), expr.AllowUndefinedVariables())\n\tif err != nil {\n\t\treturn false, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeInvalidScopeExpression, \"compile scope expression %q\", expression)\n\t}\n\toutput, err := expr.Run(program, env)\n\tif err != nil {\n\t\treturn false, errors.Wrapf(err, errors.TypeInternal, ErrCodeInvalidScopeExpression, \"run scope expression %q\", expression)\n\t}\n\tresult, ok := output.(bool)\n\tif !ok {\n\t\treturn false, errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidScopeExpression, \"scope expression %q returned non-bool value %T (%v)\", expression, output, output)\n\t}\n\treturn result, nil\n}\n","sourceCodeStart":59,"sourceCodeEnd":89,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/types/alertmanagertypes/expression.go#L59-L89","documentation":"EvalScopeExpression compiles a maintenance-window scope expression using the expr-lang evaluator against an environment built from the alert's label set. This error means the expression string failed to compile: syntax errors, unknown operators, or type conflicts with the label-derived environment (despite AllowUndefinedVariables).","triggerScenarios":"Calling ShouldSkip / EvalScopeExpression with a malformed expression such as 'env == && prod', mismatched quotes, or an expression referencing labels whose inferred types conflict with the operation.","commonSituations":"Hand-editing maintenance/scope expression YAML config; upgrading versions that change allowed expression syntax; expressions written for a different evaluator dialect pasted into scope config.","solutions":["Validate the expression syntax with expr.Compile locally before deploying config","Check for typos: unbalanced parens, missing operators, wrong quotes","Simplify the expression to label equality checks which are known-supported"],"exampleFix":"// before\nexpression := \"env == && prod\"\n\n// after\nexpression := \"env == \\\"prod\\\" && severity == \\\"critical\\\"\"","handlingStrategy":"validation","validationCode":"import (\n  \"github.com/expr-lang/expr\"\n  \"github.com/prometheus/common/model\"\n)\n\nfunc validateScopeExpr(expression string, lset model.LabelSet) error {\n    env, _ := ConvertLabelSetToEnv(lset)\n    _, err := expr.Compile(expression, expr.Env(env), expr.AllowUndefinedVariables())\n    return err\n}","typeGuard":null,"tryCatchPattern":"skip, err := EvalScopeExpression(expr, lset)\nif err != nil {\n    // documented policy: treat failure as don't skip, alert passes through\n    skip = false\n    log.Warnw(\"scope eval failed\", \"expr\", expr, \"err\", err)\n}","preventionTips":["Compile-test scope expressions in CI when config changes","Keep expressions to simple label equality/AND/OR checks"],"tags":["expr-lang","expression-evaluation","config","maintenance-window"],"backgroundTag":"expression-compile-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}