{"record":{"id":"1fff0c44f47bb5eb","repo":"caddyserver/caddy","slug":"the-first-option-must-be-one-of-the-following-s","errorCode":null,"errorMessage":"the first option must be one of the following: %s, %s, %s, %s, but got %s","messagePattern":"the first option must be one of the following: (.+?), (.+?), (.+?), (.+?), but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/fileserver/staticfiles.go","lineNumber":254,"sourceCode":"\t\tif suffix == \"\" {\n\t\t\treturn fmt.Errorf(\"precompressor does not specify a Suffix value\")\n\t\t}\n\t\tif _, ok := fsrv.precompressors[ae]; ok {\n\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\" {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/fileserver/staticfiles.go#L236-L272","documentation":"Returned in FileServer.Provision when validating browse sort_options: the first element must be one of the four recognized sort keys (name, namedirfirst, size, time — the sortByName/sortByNameDirFirst/sortBySize/sortByTime constants). Any other string in position 0 aborts provisioning.","triggerScenarios":"Configuring `sort_options` (Caddyfile) or \"sort_options\" (JSON) under file_server browse where the first entry is not one of: name, namedirfirst, size, time — e.g. 'asc' first, a typo like 'Name', or an unsupported key like 'extension'.","commonSituations":"Users writing `sort_options asc desc` (order reversed) assuming direction comes first; case mismatches; carrying over sort keys from other software (nginx/fancy-index vocabulary).","solutions":["Put a valid sort key first: name, namedirfirst, size, or time.","Put the direction (asc/desc) second, if used.","Limit the list to at most 2 entries.","Validate with `caddy validate --config Caddyfile` before reloading."],"exampleFix":"# before\nsort_options asc name\n# after\nsort_options name asc","handlingStrategy":"validation","validationCode":"# Pre-deploy check: first sort option must be a known key\nvalid=\"name namedirfirst size time\"\nfirst=$(awk '/sort_options/{print $2}' Caddyfile)\n[[ \" $valid \" == *\" $first \"* ]] || { echo \"invalid first sort option: $first\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the order contract: [name|namedirfirst|size|time] then optional [asc|desc].","Copy sort_options examples straight from the Caddy docs, not from nginx configs.","Always `caddy validate` after editing browse options."],"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"}