{"record":{"id":"bf01001f0d65c2b6","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-read-auth-file-w","errorCode":null,"errorMessage":"failed to read auth file: %w","messagePattern":"failed to read auth file: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/api/handlers/management/auth_files_crud.go","lineNumber":472,"sourceCode":"\tif h.authManager == nil {\n\t\treturn nil\n\t}\n\tauth, err := h.buildAuthFromFileData(path, data)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn h.upsertAuthRecord(ctx, auth)\n}\n\nfunc (h *Handler) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) {\n\tif path == \"\" {\n\t\treturn nil, fmt.Errorf(\"auth path is empty\")\n\t}\n\tif data == nil {\n\t\tvar err error\n\t\tdata, err = os.ReadFile(path)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to read auth file: %w\", err)\n\t\t}\n\t}\n\tmetadata := make(map[string]any)\n\tif err := json.Unmarshal(data, &metadata); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid auth file: %w\", err)\n\t}\n\tprovider, _ := metadata[\"type\"].(string)\n\tif provider == \"\" {\n\t\tprovider = \"unknown\"\n\t}\n\tlabel := provider\n\tif email, ok := metadata[\"email\"].(string); ok && email != \"\" {\n\t\tlabel = email\n\t}\n\tlastRefresh, hasLastRefresh := extractLastRefreshTimestamp(metadata)\n\n\tauthID := h.authIDForPath(path)\n\tif authID == \"\" {","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/auth_files_crud.go#L454-L490","documentation":"Thrown by buildAuthFromFileData when os.ReadFile fails on an auth-file path while no in-memory data was supplied. The management API reads credential JSON files from the auth directory to build coreauth.Auth records, and any OS-level read failure (missing file, permission, interrupted read) surfaces here. The %w wrap preserves the underlying fs error for diagnosis.","triggerScenarios":"Calling a management endpoint that imports or lists auth files (paths where data==nil is passed) when the given path has been deleted, renamed, or has mode 0600 owned by another user between listing and reading; a path outside the auth dir that does not exist.","commonSituations":"Auth files manually removed or rotated while the server runs; auth-dir misconfiguration pointing to a nonexistent directory; running the service as a different user than the owner of auths/*.json; a stale path cached from a previous config.","solutions":["Verify the file exists and is readable: ls -l on the exact path from the error's wrapped cause","Check auth-dir config and confirm the service user owns or can read auths/*.json","Re-trigger the auth-file sync/list after fixing permissions so the record is rebuilt","If the file was intentionally deleted, remove its stale record via the management API so it is not re-scanned"],"exampleFix":"# before\nchmod 600 auths/qwen.json   # owned by root, server runs as appuser\n# after\nchown appuser:appuser auths/qwen.json && chmod 600 auths/qwen.json","handlingStrategy":"validation","validationCode":"// Before triggering an auth-file scan/import:\nif info, err := os.Stat(path); err != nil || info.IsDir() {\n    return fmt.Errorf(\"auth file unavailable: %v\", err)\n}\nif info.Mode().Perm()&0o400 == 0 {\n    return errors.New(\"auth file not readable by this user\")\n}","typeGuard":"func isReadableAuthFile(path string) bool {\n    info, err := os.Stat(path)\n    return err == nil && !info.IsDir() && info.Mode().Perm()&0o400 != 0\n}","tryCatchPattern":"if auth, err := h.buildAuthFromFileData(path, nil); err != nil {\n    if os.IsNotExist(errors.Unwrap(err)) { /* stale record: skip or delete */ }\n    log.Warnf(\"skip auth file %s: %v\", path, err)\n    continue\n}","preventionTips":["Run the service as the user that owns the auths directory","Monitor the auth dir if other tooling rotates or deletes files","Health-check the auth dir (exists, readable) at startup"],"tags":["filesystem","auth","io","management-api"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}