{"record":{"id":"c04a757583994f5b","repo":"amir20/dozzle","slug":"failed-to-compile-event-expression-w","errorCode":null,"errorMessage":"failed to compile event expression: %w","messagePattern":"failed to compile event expression: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/notification/manager.go","lineNumber":233,"sourceCode":"\t\t\t\t\tif exprStr != \"\" {\n\t\t\t\t\t\tprogram, err := expr.Compile(exprStr, expr.Env(types.NotificationStat{}))\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tupdateErr = fmt.Errorf(\"failed to compile metric expression: %w\", err)\n\t\t\t\t\t\t\treturn nil, xsync.CancelOp\n\t\t\t\t\t\t}\n\t\t\t\t\t\tupdated.MetricExpression = exprStr\n\t\t\t\t\t\tupdated.MetricProgram = program\n\t\t\t\t\t} else {\n\t\t\t\t\t\tupdated.MetricExpression = \"\"\n\t\t\t\t\t\tupdated.MetricProgram = nil\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase \"eventExpression\":\n\t\t\t\tif exprStr, ok := value.(string); ok {\n\t\t\t\t\tif exprStr != \"\" {\n\t\t\t\t\t\tprogram, err := expr.Compile(exprStr, expr.Env(types.NotificationEvent{}))\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tupdateErr = fmt.Errorf(\"failed to compile event expression: %w\", err)\n\t\t\t\t\t\t\treturn nil, xsync.CancelOp\n\t\t\t\t\t\t}\n\t\t\t\t\t\tupdated.EventExpression = exprStr\n\t\t\t\t\t\tupdated.EventProgram = program\n\t\t\t\t\t} else {\n\t\t\t\t\t\tupdated.EventExpression = \"\"\n\t\t\t\t\t\tupdated.EventProgram = nil\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase \"cooldown\":\n\t\t\t\tif cd, ok := value.(int); ok {\n\t\t\t\t\tupdated.Cooldown = cd\n\t\t\t\t}\n\t\t\tcase \"sampleWindow\":\n\t\t\t\tif sw, ok := value.(int); ok {\n\t\t\t\t\tupdated.SampleWindow = sw\n\t\t\t\t\tupdated.MetricSampleBuffers = xsync.NewMap[string, *utils.RingBuffer[bool]]()\n\t\t\t\t}","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/notification/manager.go#L215-L251","documentation":"UpdateSubscription compiles a new event expression with expr-lang before storing it. If the expression string is syntactically invalid or references fields/methods that don't exist on types.NotificationEvent, the compile fails and the underlying expr error is wrapped with this message, aborting the update via xsync.CancelOp (no partial mutation).","triggerScenarios":"Calling UpdateSubscription with updates containing a non-empty eventExpression string that expr.Compile rejects: bad syntax (e.g. unbalanced parens), unknown identifiers (fields not on NotificationEvent), or wrong types in comparisons.","commonSituations":"Hand-editing notifications.yml and pasting the expression into the API/UI; typos in field names like event.Name vs event.ContainerName; using functions unavailable in the expr environment; frontend sending an expression built for a different event shape.","solutions":["Check the wrapped expr error: it names the exact token/position that failed to parse","Validate the expression against types.NotificationEvent fields and use only those identifiers","Test the expression in an expr playground or with expr.Compile(exprStr, expr.Env(types.NotificationEvent{})) in a scratch test before calling UpdateSubscription","Fix quoting/escaping if the expression was pasted from YAML or JSON where quotes were consumed"],"exampleFix":"// before\nUpdateSubscription(1, map[string]any{\"eventExpression\": \"event.level == 'error' && event.container == 'web\"}) // unterminated string\n// after\nUpdateSubscription(1, map[string]any{\"eventExpression\": \"event.Level == 'error' && event.ContainerName == 'web'\"})","handlingStrategy":"validation","validationCode":"func validEventExpr(s string) bool {\n    _, err := expr.Compile(s, expr.Env(types.NotificationEvent{}))\n    return s != \"\" && err == nil\n}","typeGuard":null,"tryCatchPattern":"if err := manager.UpdateSubscription(id, updates); err != nil {\n    var cerr interface{ Unwrap() error }\n    // log err; surface the wrapped expr compile error to the user\n}","preventionTips":["Validate expressions in the UI before calling UpdateSubscription","Keep a unit-test corpus of expressions against types.NotificationEvent","Avoid hand-editing expressions into YAML without a compile check"],"tags":["notifications","expr-lang","expression-compilation","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}