amir20/dozzle · error
failed to compile log expression
Error message
failed to compile log expression: %w
What it means
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.
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
Example fix
// before
s.LogExpression = "log.message =~ 'ERROR(' " // invalid regex/paren
// after
s.LogExpression = "log.Message =~ 'ERROR\\(' " Defensive patterns
Strategy: validation
Validate before calling
func validLogExpr(s string) error {
_, err := expr.Compile(s, expr.Env(types.NotificationLog{}))
return err
} Try / catch
if err := sub.CompileExpressions(); err != nil {
return fmt.Errorf("subscription %d rejected: %w", sub.ID, err)
} Prevention
- 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
When it happens
Trigger: AddSubscription / ReplaceSubscription / loadSubscription / compiledSub with a Subscription whose LogExpression is non-empty and fails expr.Compile(expr, expr.Env(types.NotificationLog{})).
Common situations: 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.
Related errors
- failed to compile event expression
- failed to compile container expression
- failed to compile metric expression
- failed to compile event expression
- (await res.json().catch(() =>
AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07).
Data as JSON: /api/errors/6c7f923e971b5e1b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/notification/types.go:183
}
s.TriggeredContainerIDs.Store(id, struct{}{})
}
// CompileExpressions compiles all expression strings into executable programs.
// Returns an error describing which expression failed to compile.
func (s *Subscription) CompileExpressions() error {
if s.ContainerExpression != "" {
program, err := expr.Compile(s.ContainerExpression, expr.Env(types.NotificationContainer{}))
if err != nil {
return fmt.Errorf("failed to compile container expression: %w", err)
}
s.ContainerProgram = program
}
if s.LogExpression != "" {
program, err := expr.Compile(s.LogExpression, expr.Env(types.NotificationLog{}))
if err != nil {
return fmt.Errorf("failed to compile log expression: %w", err)
}
s.LogProgram = program
}
if s.MetricExpression != "" {
program, err := expr.Compile(s.MetricExpression, expr.Env(types.NotificationStat{}))
if err != nil {
return fmt.Errorf("failed to compile metric expression: %w", err)
}
s.MetricProgram = program
}
if s.EventExpression != "" {
program, err := expr.Compile(s.EventExpression, expr.Env(types.NotificationEvent{}))
if err != nil {
return fmt.Errorf("failed to compile event expression: %w", err)
}
s.EventProgram = programView on GitHub (pinned to d9463cbe21)