{"record":{"id":"bca213a787a521b3","repo":"caddyserver/caddy","slug":"include-and-exclude-must-not-intersect-but-found","errorCode":null,"errorMessage":"include and exclude must not intersect, but found %s in both lists","messagePattern":"include and exclude must not intersect, but found (.+?) in both lists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logging.go","lineNumber":506,"sourceCode":"}\n\nfunc (cl *CustomLog) provision(ctx Context, logging *Logging) error {\n\tif err := cl.provisionCommon(ctx, logging); err != nil {\n\t\treturn err\n\t}\n\n\t// If both Include and Exclude lists are populated, then each item must\n\t// be a superspace or subspace of an item in the other list, because\n\t// populating both lists means that any given item is either a rule\n\t// or an exception to another rule. But if the item is not a super-\n\t// or sub-space of any item in the other list, it is neither a rule\n\t// nor an exception, and is a contradiction. Ensure, too, that the\n\t// sets do not intersect, which is also a contradiction.\n\tif len(cl.Include) > 0 && len(cl.Exclude) > 0 {\n\t\t// prevent intersections\n\t\tfor _, allow := range cl.Include {\n\t\t\tif slices.Contains(cl.Exclude, allow) {\n\t\t\t\treturn fmt.Errorf(\"include and exclude must not intersect, but found %s in both lists\", allow)\n\t\t\t}\n\t\t}\n\n\t\t// ensure namespaces are nested\n\touter:\n\t\tfor _, allow := range cl.Include {\n\t\t\tfor _, deny := range cl.Exclude {\n\t\t\t\tif strings.HasPrefix(allow+\".\", deny+\".\") ||\n\t\t\t\t\tstrings.HasPrefix(deny+\".\", allow+\".\") {\n\t\t\t\t\tcontinue outer\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"when both include and exclude are populated, each element must be a superspace or subspace of one in the other list; check '%s' in include\", allow)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/logging.go#L488-L524","documentation":"CustomLog validation rejects a logs entry where the same namespace appears in both include and exclude. Caddy treats these lists as rules plus exceptions; an identical entry in both is a direct contradiction, so it fails fast during config validation.","triggerScenarios":"A logs block with both include and exclude arrays that share at least one identical string, e.g. include [\"http.handlers.reverse_proxy\"] and exclude [\"http.handlers.reverse_proxy\"].","commonSituations":"Growing exclude lists incrementally until one duplicates an include entry; generated configs that concatenate lists from different sources; refactors that move a namespace from include to exclude without deleting the original.","solutions":["Find the duplicated namespace named in the error message and remove it from one of the two lists.","Decide whether the logger should emit to this sink (keep in include, drop from exclude) or not (the reverse).","Re-run caddy validate / reload and confirm the error is gone."],"exampleFix":"// before (caddyfile)\nlog my-log {\n    include http.handlers.reverse_proxy\n    exclude http.handlers.reverse_proxy\n    output file /var/log/caddy/rp.log\n}\n\n// after\nlog my-log {\n    include http.handlers.reverse_proxy\n    output file /var/log/caddy/rp.log\n}","handlingStrategy":"validation","validationCode":"// before submitting config: reject intersecting include/exclude\nfunc noIntersection(include, exclude []string) error {\n    for _, inc := range include {\n        if slices.Contains(exclude, inc) {\n            return fmt.Errorf(\"%s appears in both include and exclude\", inc)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := caddy.Validate(cfg); err != nil {\n    if strings.Contains(err.Error(), \"must not intersect\") {\n        // remove the named namespace from one list and re-validate\n    }\n    return err\n}","preventionTips":["When moving a namespace between include and exclude, delete the old entry in the same commit.","Run 'caddy validate' in CI for every config change.","Keep per-sink include/exclude lists short and single-purpose."],"tags":["logging","validation","configuration"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}