{"record":{"id":"d6da1bb8fb6b2fe3","repo":"caddyserver/caddy","slug":"unknown-try-policy-s","errorCode":null,"errorMessage":"unknown try policy %s","messagePattern":"unknown try policy (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/fileserver/matcher.go","lineNumber":305,"sourceCode":"\t// if list of files to try was omitted entirely, assume URL path\n\t// (use placeholder instead of r.URL.Path; see issue #4146)\n\tif m.TryFiles == nil {\n\t\tm.TryFiles = []string{\"{http.request.uri.path}\"}\n\t}\n\treturn nil\n}\n\n// Validate ensures m has a valid configuration.\nfunc (m MatchFile) Validate() error {\n\tswitch m.TryPolicy {\n\tcase \"\",\n\t\ttryPolicyFirstExist,\n\t\ttryPolicyFirstExistFallback,\n\t\ttryPolicyLargestSize,\n\t\ttryPolicySmallestSize,\n\t\ttryPolicyMostRecentlyMod:\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown try policy %s\", m.TryPolicy)\n\t}\n\treturn nil\n}\n\n// Match returns true if r matches m. Returns true\n// if a file was matched. If so, four placeholders\n// will be available:\n//   - http.matchers.file.relative: Path to file relative to site root\n//   - http.matchers.file.absolute: Path to file including site root\n//   - http.matchers.file.type: file or directory\n//   - http.matchers.file.remainder: Portion remaining after splitting file path (if configured)\nfunc (m MatchFile) Match(r *http.Request) bool {\n\tmatch, err := m.selectFile(r)\n\tif err != nil {\n\t\t// nolint:staticcheck\n\t\tcaddyhttp.SetVar(r.Context(), caddyhttp.MatcherErrorVarKey, err)\n\t}\n\treturn match","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/fileserver/matcher.go#L287-L323","documentation":"Validate-time error from MatchFile: TryPolicy is not one of the empty string, first_exist, first_exist_fallback, largest_size, smallest_size, or most_recently_modified. The file matcher rejects unknown policy strings at config validation.","triggerScenarios":"try_files policy typo in JSON (\"try_policy\": \"first-exist\") or a policy name from docs of a different version.","commonSituations":"Hand-written JSON using hyphens instead of underscores; policies renamed across Caddy versions; copy-paste from try_files directives expecting nginx semantics.","solutions":["Use exactly: first_exist, first_exist_fallback, largest_size, smallest_size, or most_recently_modified","Omit try_policy to get the default (first_exist)","Run caddy validate against the config before deploying"],"exampleFix":"// before\n{\"try_policy\": \"first-exist\"}\n// after\n{\"try_policy\": \"first_exist\"}","handlingStrategy":"validation","validationCode":"var validPolicies = map[string]bool{\"\": true, \"first_exist\": true, \"first_exist_fallback\": true, \"largest_size\": true, \"smallest_size\": true, \"most_recently_modified\": true}\nif !validPolicies[policy] { return fmt.Errorf(\"unknown try policy %s\", policy) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use snake_case policy names exactly as documented","Run caddy validate on all configs in CI"],"tags":["caddy","fileserver","matcher","validation","config"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}