{"record":{"id":"352defc739622076","repo":"xtekky/gpt4free","slug":"file-access-error","errorCode":"FILE_ACCESS_ERROR","errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"TokenManagerError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/qwen/sharedTokenManager.py","lineNumber":132,"sourceCode":"\n    def checkAndReloadIfNeeded(self):\n        now = int(time.time() * 1000)\n        if now - self.memory_cache[\"last_check\"] < CACHE_CHECK_INTERVAL_MS:\n            return\n        self.memory_cache[\"last_check\"] = now\n\n        try:\n            file_path = self.getCredentialFilePath()\n            stat = file_path.stat()\n            file_mod_time = int(stat.st_mtime * 1000)\n            if file_mod_time > self.memory_cache[\"file_mod_time\"]:\n                self.reloadCredentialsFromFile()\n                self.memory_cache[\"file_mod_time\"] = file_mod_time\n        except FileNotFoundError:\n            self.memory_cache[\"file_mod_time\"] = 0\n        except Exception as e:\n            self.memory_cache[\"credentials\"] = None\n            raise TokenManagerError(TokenError.FILE_ACCESS_ERROR, str(e), e)\n\n    def reloadCredentialsFromFile(self):\n        file_path = self.getCredentialFilePath()\n        debug.log(f\"Reloading credentials from {file_path}\")\n        try:\n            with open(file_path, \"r\") as fs:\n                data = json.load(fs)\n                credentials = self.validateCredentials(data)\n                self.memory_cache[\"credentials\"] = credentials\n        except FileNotFoundError as e:\n            self.memory_cache[\"credentials\"] = None\n            raise TokenManagerError(\n                TokenError.FILE_ACCESS_ERROR, \"Credentials file not found\", e\n            ) from e\n        except json.JSONDecodeError as e:\n            self.memory_cache[\"credentials\"] = None\n            raise TokenManagerError(\n                TokenError.FILE_ACCESS_ERROR, \"Invalid JSON format\", e","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/qwen/sharedTokenManager.py#L114-L150","documentation":"TokenManagerError with code FILE_ACCESS_ERROR raised in SharedTokenManager.checkAndReloadIfNeeded (sharedTokenManager.py:132) when stat()ting or reloading the on-disk credentials file raises something other than FileNotFoundError (which is tolerated). The in-memory credentials are cleared, so subsequent calls will demand re-authentication or a successful reload.","triggerScenarios":"The mtime-based hot-reload check fails with PermissionError (unreadable/ownership-changed file), OSError (directory removed, disk full), or a reload-time parse/validation error — any non-FileNotFound exception hits this handler.","commonSituations":"Credentials file created by root then read by a normal user (or vice versa) after a privilege change; file on a network mount that went away; concurrent writers leaving the file locked; security software blocking reads.","solutions":["Check file permissions on the credentials path (ls -l) and chown/chmod so the running user can read it","Verify the credentials directory still exists and the disk isn't full","If another process is rewriting the file, ensure writes are atomic (write temp + rename)","Restore or regenerate the credentials file, then retry"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import os\n\ndef credentials_file_accessible(path) -> bool:\n    try:\n        os.stat(path)\n        with open(path, \"r\") as f:\n            f.read(1)\n        return True\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    manager.checkAndReloadIfNeeded()\nexcept TokenManagerError as e:\n    if \"FILE_ACCESS\" in str(e.error):\n        logger.error(\"credentials file unreadable: %s\", e.message)\n        fix_credentials_permissions()  # or alert operator\n    raise","preventionTips":["Run the app under a user that owns the credentials file","Keep the credentials directory on local, writable storage","Write credentials atomically to avoid half-written states"],"tags":["qwen","credentials","file-io","permissions"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}