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
- Close other applications that might be locking the file (antivirus, backup, file watchers)
- Check file and directory permissions — the process needs delete permission
- Retry the clear operation — transient locks often release
- If persistent, manually delete the `{hash}_oauth.json` file from the config directory
- 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
- Treat clear failures as non-fatal — the goal (removing OAuth state) can often be achieved by overwriting the file instead
- Retry clear after a short delay if the file is locked by another process
- On Windows, be aware of antivirus/file watcher locks that can temporarily block deletion
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
- Failed to read OAuth storage: ${error instanceof Error ? err
- Failed to write OAuth storage: ${error instanceof Error ? er
- No code verifier saved for session
- OAuth authentication failed: ${oauthError instanceof Error ?
- User denied the Feishu app registration
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/f8eec0859cd196d2.
Report an issue: GitHub.