xtekky/gpt4free · error · TokenManagerError

FILE_ACCESS_ERROR

FILE_ACCESS_ERROR

Error message

{e}

What it means

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.

Source

Thrown at g4f/Provider/qwen/sharedTokenManager.py:132

    def checkAndReloadIfNeeded(self):
        now = int(time.time() * 1000)
        if now - self.memory_cache["last_check"] < CACHE_CHECK_INTERVAL_MS:
            return
        self.memory_cache["last_check"] = now

        try:
            file_path = self.getCredentialFilePath()
            stat = file_path.stat()
            file_mod_time = int(stat.st_mtime * 1000)
            if file_mod_time > self.memory_cache["file_mod_time"]:
                self.reloadCredentialsFromFile()
                self.memory_cache["file_mod_time"] = file_mod_time
        except FileNotFoundError:
            self.memory_cache["file_mod_time"] = 0
        except Exception as e:
            self.memory_cache["credentials"] = None
            raise TokenManagerError(TokenError.FILE_ACCESS_ERROR, str(e), e)

    def reloadCredentialsFromFile(self):
        file_path = self.getCredentialFilePath()
        debug.log(f"Reloading credentials from {file_path}")
        try:
            with open(file_path, "r") as fs:
                data = json.load(fs)
                credentials = self.validateCredentials(data)
                self.memory_cache["credentials"] = credentials
        except FileNotFoundError as e:
            self.memory_cache["credentials"] = None
            raise TokenManagerError(
                TokenError.FILE_ACCESS_ERROR, "Credentials file not found", e
            ) from e
        except json.JSONDecodeError as e:
            self.memory_cache["credentials"] = None
            raise TokenManagerError(
                TokenError.FILE_ACCESS_ERROR, "Invalid JSON format", e

View on GitHub (pinned to 973504e177)

Solutions

  1. Check file permissions on the credentials path (ls -l) and chown/chmod so the running user can read it
  2. Verify the credentials directory still exists and the disk isn't full
  3. If another process is rewriting the file, ensure writes are atomic (write temp + rename)
  4. Restore or regenerate the credentials file, then retry
Defensive patterns

Strategy: validation

Validate before calling

import os

def credentials_file_accessible(path) -> bool:
    try:
        os.stat(path)
        with open(path, "r") as f:
            f.read(1)
        return True
    except OSError:
        return False

Try / catch

try:
    manager.checkAndReloadIfNeeded()
except TokenManagerError as e:
    if "FILE_ACCESS" in str(e.error):
        logger.error("credentials file unreadable: %s", e.message)
        fix_credentials_permissions()  # or alert operator
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/352defc739622076. Report an issue: GitHub.