{"record":{"id":"88f2306841162138","repo":"amir20/dozzle","slug":"failed-to-compile-container-expression-w","errorCode":null,"errorMessage":"failed to compile container expression: %w","messagePattern":"failed to compile container expression: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/notification/manager.go","lineNumber":192,"sourceCode":"\t\tfor key, value := range updates {\n\t\t\tswitch key {\n\t\t\tcase \"name\":\n\t\t\t\tif name, ok := value.(string); ok {\n\t\t\t\t\tupdated.Name = name\n\t\t\t\t}\n\t\t\tcase \"enabled\":\n\t\t\t\tif enabled, ok := value.(bool); ok {\n\t\t\t\t\tupdated.Enabled = enabled\n\t\t\t\t}\n\t\t\tcase \"dispatcherId\":\n\t\t\t\tif dispatcherID, ok := value.(int); ok {\n\t\t\t\t\tupdated.DispatcherID = dispatcherID\n\t\t\t\t}\n\t\t\tcase \"containerExpression\":\n\t\t\t\tif exprStr, ok := value.(string); ok {\n\t\t\t\t\tprogram, err := expr.Compile(exprStr, expr.Env(types.NotificationContainer{}))\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tupdateErr = fmt.Errorf(\"failed to compile container expression: %w\", err)\n\t\t\t\t\t\treturn nil, xsync.CancelOp\n\t\t\t\t\t}\n\t\t\t\t\tupdated.ContainerExpression = exprStr\n\t\t\t\t\tupdated.ContainerProgram = program\n\t\t\t\t}\n\t\t\tcase \"logExpression\":\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.NotificationLog{}))\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tupdateErr = fmt.Errorf(\"failed to compile log 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.LogExpression = exprStr\n\t\t\t\t\t\tupdated.LogProgram = program\n\t\t\t\t\t} else {\n\t\t\t\t\t\tupdated.LogExpression = \"\"\n\t\t\t\t\t\tupdated.LogProgram = nil","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/notification/manager.go#L174-L210","documentation":"When UpdateSubscription receives a \"containerExpression\" field, it compiles the string with the expr-lang expression compiler against the types.NotificationContainer environment before accepting it. This error wraps expr.Compile failures: syntax errors, unknown identifiers/functions, or type-incorrect operations for that environment. The update is cancelled and the subscription is left unchanged.","triggerScenarios":"Submitting an update map with key \"containerExpression\" set to a string that is not a valid expr program over NotificationContainer, e.g. a wrong field name, unbalanced parentheses, or comparing incompatible types.","commonSituations":"Users hand-writing container filter expressions in the alert UI with typos (continer.Name), using fields that belong to NotificationLog instead, or copying expressions from another tool with different syntax.","solutions":["Read the wrapped expr.Compile error, which names the exact syntax/type problem and position.","Restrict the expression to fields defined on types.NotificationContainer (check the struct definition).","Validate the expression in the UI (or a scratch expr run) before calling UpdateSubscription."],"exampleFix":"// before (field not on NotificationContainer)\nupdates := map[string]any{\"containerExpression\": \"log.Level == 'error'\"}\n// after\nupdates := map[string]any{\"containerExpression\": \"container.Name == \\\"nginx\\\"\"}","handlingStrategy":"validation","validationCode":"if exprStr, ok := updates[\"containerExpression\"].(string); ok {\n    if _, err := expr.Compile(exprStr, expr.Env(types.NotificationContainer{})); err != nil {\n        return fmt.Errorf(\"invalid containerExpression: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := manager.UpdateSubscription(id, updates); err != nil {\n    var ce *expr.Error\n    if errors.As(err, &ce) {\n        return fmt.Errorf(\"expression error at offset %d: %v\", ce.Offset, ce)\n    }\n    return err\n}","preventionTips":["Validate expressions in the UI before submitting updates.","Only reference fields from types.NotificationContainer.","Keep a library of tested expressions to copy from."],"tags":["expression","validation","notifications"],"backgroundTag":"expression-compilation-failed","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"}