{"record":{"id":"e3fcd71c35fb55f7","repo":"caddyserver/caddy","slug":"the-second-option-must-be-one-of-the-following-s","errorCode":null,"errorMessage":"the second option must be one of the following: %s, %s, but got %s","messagePattern":"the second option must be one of the following: (.+?), (.+?), but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/fileserver/staticfiles.go","lineNumber":258,"sourceCode":"\t\t\treturn fmt.Errorf(\"precompressor already added: %s\", ae)\n\t\t}\n\t\tif fsrv.precompressors == nil {\n\t\t\tfsrv.precompressors = make(map[string]encode.Precompressed)\n\t\t}\n\t\tfsrv.precompressors[ae] = p\n\t}\n\n\tif fsrv.Browse != nil {\n\t\t// check sort options\n\t\tfor idx, sortOption := range fsrv.Browse.SortOptions {\n\t\t\tswitch idx {\n\t\t\tcase 0:\n\t\t\t\tif sortOption != sortByName && sortOption != sortByNameDirFirst && sortOption != sortBySize && sortOption != sortByTime {\n\t\t\t\t\treturn fmt.Errorf(\"the first option must be one of the following: %s, %s, %s, %s, but got %s\", sortByName, sortByNameDirFirst, sortBySize, sortByTime, sortOption)\n\t\t\t\t}\n\t\t\tcase 1:\n\t\t\t\tif sortOption != sortOrderAsc && sortOption != sortOrderDesc {\n\t\t\t\t\treturn fmt.Errorf(\"the second option must be one of the following: %s, %s, but got %s\", sortOrderAsc, sortOrderDesc, sortOption)\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"only max 2 sort options are allowed, but got %d\", idx+1)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {\n\trepl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)\n\n\tif runtime.GOOS == \"windows\" {\n\t\t// reject paths with Alternate Data Streams (ADS)\n\t\tif strings.Contains(r.URL.Path, \":\") {\n\t\t\treturn caddyhttp.Error(http.StatusBadRequest, fmt.Errorf(\"illegal ADS path\"))\n\t\t}","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/fileserver/staticfiles.go#L240-L276","documentation":"Returned in FileServer.Provision when validating browse sort_options: the second element, when present, must be a sort direction — either asc or desc (sortOrderAsc/sortOrderDesc). The second slot cannot hold another sort key; only one key plus one direction is allowed.","triggerScenarios":"sort_options with a second entry that is not 'asc' or 'desc', e.g. `sort_options name size` or `sort_options time namedirfirst`.","commonSituations":"Attempting to sort by two keys (not supported); typos like 'ascending'/'descending'; assuming the second option is another field name.","solutions":["Use only 'asc' or 'desc' as the second option.","If you wanted multi-key sorting, remove the extra key — the browse feature supports one key plus direction.","Re-run `caddy validate` after fixing."],"exampleFix":"# before\nsort_options name size\n# after\nsort_options name desc","handlingStrategy":"validation","validationCode":"# Pre-deploy check: second sort option, if present, must be asc or desc\nsecond=$(awk '/sort_options/{print $3}' Caddyfile)\nif [ -n \"$second\" ] && [ \"$second\" != \"asc\" ] && [ \"$second\" != \"desc\" ]; then\n  echo \"invalid second sort option: $second (want asc|desc)\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The second slot is a direction, never a second sort key.","Multi-key sorting is unsupported — design browse templates around one key + direction.","Use exactly the tokens 'asc'/'desc', lowercase."],"tags":["caddy","fileserver","browse","sort-options","config-validation"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}