SigNoz/signoz · warning
ErrCodeInvalidScopeExpression
ErrCodeInvalidScopeExpression
Error message
compile scope expression %q
What it means
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).
Source
Thrown at pkg/types/alertmanagertypes/expression.go:77
// (nested wins) and flag.
if _, isMap := env[key].(map[string]any); isMap {
conflict = true
continue
}
env[key] = value
}
return env, conflict
}
// EvalScopeExpression compiles and runs the expression against the provided
// labels. It returns (result, error). Callers should log the error and
// decide how to handle a failed evaluation (the maintenance muter treats a
// failure as "don't skip" so alerts pass through).
func EvalScopeExpression(expression string, lset model.LabelSet) (bool, error) {
env, _ := ConvertLabelSetToEnv(lset)
program, err := expr.Compile(expression, expr.Env(env), expr.AllowUndefinedVariables())
if err != nil {
return false, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeInvalidScopeExpression, "compile scope expression %q", expression)
}
output, err := expr.Run(program, env)
if err != nil {
return false, errors.Wrapf(err, errors.TypeInternal, ErrCodeInvalidScopeExpression, "run scope expression %q", expression)
}
result, ok := output.(bool)
if !ok {
return false, errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidScopeExpression, "scope expression %q returned non-bool value %T (%v)", expression, output, output)
}
return result, nil
}
View on GitHub (pinned to 5069bf80b0)
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
Example fix
// before expression := "env == && prod" // after expression := "env == \"prod\" && severity == \"critical\""
Defensive patterns
Strategy: validation
Validate before calling
import (
"github.com/expr-lang/expr"
"github.com/prometheus/common/model"
)
func validateScopeExpr(expression string, lset model.LabelSet) error {
env, _ := ConvertLabelSetToEnv(lset)
_, err := expr.Compile(expression, expr.Env(env), expr.AllowUndefinedVariables())
return err
} Try / catch
skip, err := EvalScopeExpression(expr, lset)
if err != nil {
// documented policy: treat failure as don't skip, alert passes through
skip = false
log.Warnw("scope eval failed", "expr", expr, "err", err)
} Prevention
- Compile-test scope expressions in CI when config changes
- Keep expressions to simple label equality/AND/OR checks
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28).
Data as JSON: /api/errors/cefe25b5d9f4a090.
Report an issue: GitHub.