{"record":{"id":"a26c97c90a537d83","repo":"kataras/iris","slug":"unexpected-file-extension-s","errorCode":null,"errorMessage":"unexpected file extension: %s","messagePattern":"unexpected file extension: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/basicauth/user.go","lineNumber":225,"sourceCode":"\n\t// We use unmarshal instead of file decoder\n\t// as we may need to read it more than once (dests, see below).\n\tvar (\n\t\tunmarshal func(data []byte, v any) error\n\t\text       string\n\t)\n\n\tif idx := strings.LastIndexByte(src, '.'); idx > 0 {\n\t\text = src[idx:]\n\t}\n\n\tswitch ext {\n\tcase \"\", \".json\":\n\t\tunmarshal = json.Unmarshal\n\tcase \".yml\", \".yaml\":\n\t\tunmarshal = yaml.Unmarshal\n\tdefault:\n\t\treturn fmt.Errorf(\"unexpected file extension: %s\", ext)\n\t}\n\n\tvar (\n\t\tok      bool\n\t\tlastErr error\n\t)\n\n\tfor _, d := range dest {\n\t\tif err = unmarshal(data, d); err == nil {\n\t\t\tok = true\n\t\t} else {\n\t\t\tlastErr = err\n\t\t}\n\t}\n\n\tif !ok {\n\t\treturn lastErr\n\t}","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/basicauth/user.go#L207-L243","documentation":"basicauth.AllowUsersFile loads basic-auth users from a file, and decodeFile dispatches on the file extension to choose JSON or YAML unmarshalling. Any extension other than .json, .yml, .yaml (or no extension) is rejected with this error before any parsing happens.","triggerScenarios":"Calling AllowUsersFile(\"users.txt\"), (\"users.toml\"), (\"auth.conf\"), or any path whose filepath.Ext is not .json/.yml/.yaml/.yaml variants or empty.","commonSituations":"Pointing the option at a .txt, .csv, or .toml file, uppercase extensions like .JSON depending on Ext matching, or generated temp files with random extensions.","solutions":["Rename the users file to users.json, users.yml, or users.yaml and ensure its content matches that format.","If the data is JSON in a differently-named file, copy/rename rather than changing format.","Convert other formats (TOML, CSV) to YAML/JSON before passing the path to AllowUsersFile."],"exampleFix":"// before\nopts := basicauth.Options{AllowUsersFile: \"./users.txt\"}\n\n// after\nopts := basicauth.Options{AllowUsersFile: \"./users.json\"}","handlingStrategy":"validation","validationCode":"ext := filepath.Ext(path); switch ext { case \"\", \".json\", \".yml\", \".yaml\": default: return fmt.Errorf(\"unsupported: %s\", ext) }","typeGuard":"func hasSupportedUsersFileExt(path string) bool { e := filepath.Ext(path); return e == \"\" || e == \".json\" || e == \".yml\" || e == \".yaml\" }","tryCatchPattern":"err := opts.Apply(...); if err != nil && strings.HasPrefix(err.Error(), \"unexpected file extension\") { log.Fatalf(\"rename users file to .json/.yml/.yaml: %v\", err) }","preventionTips":["Keep the users file extension in .json/.yml/.yaml and match its content to that format.","Validate the file exists and has a supported extension at startup.","Convert TOML/CSV sources to YAML/JSON in a build step."],"tags":["go","iris","basicauth","file-extension","configuration"],"backgroundTag":"unsupported-file-format","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}