CherryHQ/cherry-studio · warning · Error

Failed to clear OAuth storage: ${error instanceof Error ? er

Error message

Failed to clear OAuth storage: ${error instanceof Error ? error.message : String(error)}

What it means

Thrown by `clear()` when deleting the OAuth storage file fails with an error other than ENOENT (file-not-found is silently ignored as a no-op since the goal — file absence — is already achieved). Any other unlink error (permissions, disk I/O, file locked) is wrapped and thrown.

Source

Thrown at src/main/ai/mcp/oauth/storage.ts:132

    return data.authServerUrl
  }

  async saveAuthServerUrl(url: string | undefined): Promise<void> {
    const data = await this.readStorage()
    await this.writeStorage({
      ...data,
      authServerUrl: url
    })
  }

  async clear(): Promise<void> {
    try {
      await fs.unlink(this.filePath)
      this.cache = null
    } catch (error) {
      if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
        logger.error('Error clearing OAuth storage:', error as Error)
        throw new Error(`Failed to clear OAuth storage: ${error instanceof Error ? error.message : String(error)}`)
      }
    }
  }
}

View on GitHub (pinned to 726446b54c)

Solutions

  1. Close other applications that might be locking the file (antivirus, backup, file watchers)
  2. Check file and directory permissions — the process needs delete permission
  3. Retry the clear operation — transient locks often release
  4. If persistent, manually delete the `{hash}_oauth.json` file from the config directory
  5. On Windows, use Process Explorer to identify which process holds the file handle
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await oauthStorage.clear()
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Failed to clear OAuth storage')) {
    // Non-fatal — file deletion is best-effort cleanup
    logger.warn('Could not delete OAuth storage file', e)
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling `clear()` to remove the OAuth JSON file, but `fs.unlink()` fails with EACCES (permission denied), EBUSY (file locked by another process), or a disk I/O error. ENOENT is the only error code silently swallowed.

Common situations: Antivirus or backup software locking the file on Windows; file permissions were changed after creation; the file is on a network mount with intermittent connectivity; the process doesn't have delete permission on the directory.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/f8eec0859cd196d2. Report an issue: GitHub.