{"record":{"id":"6c7f923e971b5e1b","repo":"amir20/dozzle","slug":"failed-to-compile-log-expression-w-6c7f92","errorCode":null,"errorMessage":"failed to compile log expression: %w","messagePattern":"failed to compile log expression: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/notification/types.go","lineNumber":183,"sourceCode":"\t}\n\ts.TriggeredContainerIDs.Store(id, struct{}{})\n}\n\n// CompileExpressions compiles all expression strings into executable programs.\n// Returns an error describing which expression failed to compile.\nfunc (s *Subscription) CompileExpressions() error {\n\tif s.ContainerExpression != \"\" {\n\t\tprogram, err := expr.Compile(s.ContainerExpression, expr.Env(types.NotificationContainer{}))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile container expression: %w\", err)\n\t\t}\n\t\ts.ContainerProgram = program\n\t}\n\n\tif s.LogExpression != \"\" {\n\t\tprogram, err := expr.Compile(s.LogExpression, expr.Env(types.NotificationLog{}))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile log expression: %w\", err)\n\t\t}\n\t\ts.LogProgram = program\n\t}\n\n\tif s.MetricExpression != \"\" {\n\t\tprogram, err := expr.Compile(s.MetricExpression, expr.Env(types.NotificationStat{}))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile metric expression: %w\", err)\n\t\t}\n\t\ts.MetricProgram = program\n\t}\n\n\tif s.EventExpression != \"\" {\n\t\tprogram, err := expr.Compile(s.EventExpression, expr.Env(types.NotificationEvent{}))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to compile event expression: %w\", err)\n\t\t}\n\t\ts.EventProgram = program","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/notification/types.go#L165-L201","documentation":"CompileExpressions compiles LogExpression with expr against types.NotificationLog. Invalid syntax or identifiers not present on NotificationLog cause expr.Compile to fail and this wrapped error is returned, leaving LogProgram unset.","triggerScenarios":"AddSubscription / ReplaceSubscription / loadSubscription / compiledSub with a Subscription whose LogExpression is non-empty and fails expr.Compile(expr, expr.Env(types.NotificationLog{})).","commonSituations":"Writing log-level rules with wrong field names (e.g. log.msg vs the actual message field); regex literals with unescaped characters; reusing container-style expressions on logs.","solutions":["Inspect the wrapped expr error for token/position details","Restrict the expression to fields on types.NotificationLog","Pre-validate the expression with expr.Compile in a test using the NotificationLog env","Correct quoting/escaping, especially for regex-like patterns inside YAML"],"exampleFix":"// before\ns.LogExpression = \"log.message =~ 'ERROR(' \" // invalid regex/paren\n// after\ns.LogExpression = \"log.Message =~ 'ERROR\\\\(' \"","handlingStrategy":"validation","validationCode":"func validLogExpr(s string) error {\n    _, err := expr.Compile(s, expr.Env(types.NotificationLog{}))\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := sub.CompileExpressions(); err != nil {\n    return fmt.Errorf(\"subscription %d rejected: %w\", sub.ID, err)\n}","preventionTips":["Pre-validate log expressions with the NotificationLog env","Escape regex special characters properly inside YAML strings","Keep a test that compiles every stored subscription at startup"],"tags":["notifications","expr-lang","expression-compilation"],"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"}