{"record":{"id":"4b1f58e0a1739e00","repo":"caddyserver/caddy","slug":"server-block-v-v","errorCode":null,"errorMessage":"server block %v: %v","messagePattern":"server block (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"caddyconfig/httpcaddyfile/httptype.go","lineNumber":1663,"sourceCode":"\tfor _, mp := range matcherPairs {\n\t\tmatcherSet := make(map[string]caddyhttp.RequestMatcherWithError)\n\t\tif len(mp.hostm) > 0 {\n\t\t\tmatcherSet[\"host\"] = mp.hostm\n\t\t}\n\t\tif len(mp.pathm) > 0 {\n\t\t\tmatcherSet[\"path\"] = mp.pathm\n\t\t}\n\t\tif len(matcherSet) > 0 {\n\t\t\tmatcherSets = append(matcherSets, matcherSet)\n\t\t}\n\t}\n\n\t// finally, encode each of the matcher sets\n\tmatcherSetsEnc := make([]caddy.ModuleMap, 0, len(matcherSets))\n\tfor _, ms := range matcherSets {\n\t\tmsEncoded, err := encodeMatcherSet(ms)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"server block %v: %v\", sblock.block.Keys, err)\n\t\t}\n\t\tmatcherSetsEnc = append(matcherSetsEnc, msEncoded)\n\t}\n\n\treturn matcherSetsEnc, nil\n}\n\nfunc parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.ModuleMap) error {\n\td.Next() // advance to the first token\n\n\t// this is the \"name\" for \"named matchers\"\n\tdefinitionName := d.Val()\n\n\tif _, ok := matchers[definitionName]; ok {\n\t\treturn fmt.Errorf(\"matcher is defined more than once: %s\", definitionName)\n\t}\n\tmatchers[definitionName] = make(caddy.ModuleMap)\n","sourceCodeStart":1645,"sourceCodeEnd":1681,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/caddyconfig/httpcaddyfile/httptype.go#L1645-L1681","documentation":"A wrapper error from compileEncodedMatcherSets: encoding one of the server block's compiled matcher sets into a caddy.ModuleMap failed. The inner error typically comes from encodeMatcherSet rejecting a matcher module whose JSON cannot be produced, and the message prefixes the block's keys so you know which site block is at fault.","triggerScenarios":"A site block whose host/path matcher combination includes values that fail encoding — e.g. a placeholder or regexp that cannot marshal into the module map; practically rare with stock matchers, more likely with custom matcher modules returning non-serializable configs from their UnmarshalCaddyfile.","commonSituations":"Custom matcher plugins with broken MarshalJSON, or malformed hostnames/placeholders in site keys; also seen when a config generated by tooling feeds unexpected values into matcher fields.","solutions":["Read the inner error — it identifies the failing matcher value; correct it in the named site block","If a custom matcher plugin is involved, fix its JSON marshaling or update the plugin","Reproduce with `caddy adapt` on the single block to minimize input","Simplify the block's matchers and re-add them one by one to isolate the bad one"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Programmatically: round-trip each matcher set before use\nif _, err := json.Marshal(matcherSet); err != nil {\n    return fmt.Errorf(\"block %v: unencodable matcher: %w\", keys, err)\n}","typeGuard":null,"tryCatchPattern":"msEncoded, err := encodeMatcherSet(ms)\nif err != nil {\n    return nil, fmt.Errorf(\"server block %v: %w\", sblock.block.Keys, err)\n}","preventionTips":["For custom matcher modules, implement/verify MarshalJSON and test round-trip","Validate generated configs with caddy adapt before loading","Keep matcher values to plain strings/placeholders the stock encoder handles"],"tags":["caddy","caddyfile","matchers","json"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}