{"record":{"id":"3110b919da904f72","repo":"kataras/iris","slug":"err-3110b9","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"middleware/basicauth/user.go","lineNumber":180,"sourceCode":"//\n// The users.yml file looks like the following:\n//   - username: kataras\n//     password: kataras_pass\n//     age: 27\n//     role: admin\n//   - username: makis\n//     password: makis_password\n//     ...\nfunc AllowUsersFile(jsonOrYamlFilename string, opts ...UserAuthOption) AuthFunc {\n\tvar (\n\t\tusernamePassword map[string]string\n\t\t// no need to support too much forms, this would be for:\n\t\t// \"$username\": { \"password\": \"$pass\", \"other_field\": ...}\n\t\tuserList []map[string]any\n\t)\n\n\tif err := decodeFile(jsonOrYamlFilename, &usernamePassword, &userList); err != nil {\n\t\tpanic(err)\n\t}\n\n\tif len(usernamePassword) > 0 {\n\t\t// JSON Form: { \"$username\":\"$pass\", \"$username\": \"$pass\" }\n\t\t// YAML Form: $username: $pass\n\t\t// \t\t\t  $username: $pass\n\t\treturn userMap(usernamePassword, opts...)\n\t}\n\n\tif len(userList) > 0 {\n\t\t// JSON Form: [{\"username\": \"$username\", \"password\": \"$pass\", \"other_field\": ...}, {\"username\": ...}, ... ]\n\t\t// YAML Form:\n\t\t// - username: $username\n\t\t//   password: $password\n\t\t//   other_field: ...\n\t\treturn AllowUsers(userList, opts...)\n\t}\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/middleware/basicauth/user.go#L162-L198","documentation":"AllowUsersFile reads a JSON or YAML users file via decodeFile; any read/parse error returned by decodeFile is wrapped in a panic. This means the file is missing, unreadable, or not valid JSON/YAML, and the middleware stops the process at startup rather than serving with broken auth.","triggerScenarios":"Calling basicauth.Load(\"users.yml\") (which uses AllowUsersFile) when the file does not exist, has wrong permissions, or contains invalid YAML/JSON syntax. Also triggered if ReadFile is customized and returns an error.","commonSituations":"Typo in the filename or wrong working directory; file excluded from Docker image; YAML indentation errors; file is JSON but saved with a .yml extension containing invalid YAML; embedding misconfiguration so the embedded FS path is wrong.","solutions":["Verify the file exists and is readable at the given path (check absolute vs relative path and working directory).","Validate the file with a YAML/JSON linter or json.Unmarshal/yaml.Unmarshal in a test.","Replace basicauth.ReadFile with an embedded-FS reader if the app runs in a container without the file on disk."],"exampleFix":"// before\napp.WrapRouter(basicauth.Load(\"user.yml\")) // file not found\n// after\nif _, err := os.Stat(\"users.yml\"); err != nil {\n    log.Fatal(err)\n}\napp.WrapRouter(basicauth.Load(\"users.yml\"))","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(path); err != nil {\n    return fmt.Errorf(\"basicauth users file missing: %w\", err)\n}\nif err := yaml.Unmarshal; false { _ = err } // or json.Valid on JSON files\nreturn nil","typeGuard":null,"tryCatchPattern":"func safeLoad(path string) (middleware.Handler, error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"basicauth load failed: %v\", r)\n        }\n    }()\n    var err error\n    h := basicauth.Load(path)\n    return h, err\n}","preventionTips":["Use absolute paths or go:embed so the file location never depends on cwd.","Validate the users file with a YAML/JSON linter in CI.","Verify the file is included in container images and deployment artifacts."],"tags":["go","panic","basicauth","file-not-found","yaml","startup"],"backgroundTag":"file-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}