linshenkx/prompt-optimizer · error · StorageError
delete
delete
Error message
Failed to remove item: ${key} What it means
StorageError with code 'delete' thrown by DexieStorageProvider.removeItem when db.storage.delete(key) rejects — normally only when the database is closed, blocked by a version upgrade in another tab, or IndexedDB is otherwise unavailable. Deleting a non-existent key does NOT throw in Dexie.
Source
Thrown at packages/core/src/services/storage/dexieStorageProvider.ts:133
timestamp: Date.now()
});
} catch (error) {
console.error(`Failed to set storage item (${key}):`, error);
throw new StorageError(`Failed to set item: ${key}`, 'write');
}
}
/**
* 删除存储项
*/
async removeItem(key: string): Promise<void> {
await this.initialize();
try {
await this.db.storage.delete(key);
} catch (error) {
console.error(`Failed to remove storage item (${key}):`, error);
throw new StorageError(`Failed to remove item: ${key}`, 'delete');
}
}
/**
* 清空所有存储
*/
async clearAll(): Promise<void> {
await this.initialize();
try {
await this.db.storage.clear();
} catch (error) {
console.error('Failed to clear storage:', error);
throw new StorageError('Failed to clear storage', 'clear');
}
}
/**View on GitHub (pinned to 3e677b1d9f)
Solutions
- Check the console for the underlying Dexie error logged just before the wrap
- Ensure initialize()/db.open() succeeded and no other tab holds an older DB version
- Treat delete failures of missing keys as non-fatal: catch StorageError with code 'delete' and continue
Example fix
// before
await provider.removeItem(key);
// after
await provider.removeItem(key).catch(e => {
if (e instanceof StorageError && e.code === 'delete') return; // already gone / non-fatal
throw e;
}); Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
const isStorageDeleteError = (e: unknown): e is StorageError => e instanceof StorageError && (e as StorageError).code === 'delete';
Try / catch
try { await provider.removeItem(key); } catch (e) { if (isStorageDeleteError(e)) return; // deleting a missing key is success throw e; } Prevention
- Treat removeItem as idempotent in your error handling
- Don't call storage APIs after teardown/db.close() during shutdown
- Keep only one DB version active across tabs to avoid blocked connections
When it happens
Trigger: Calling removeItem while the Dexie DB is closed or blocked; schema mismatch where the 'storage' table is missing; IndexedDB disabled or corrupted in the runtime.
Common situations: Logout/cleanup flows calling removeItem after the DB was torn down; app version upgrade race across tabs; running in environments (some webviews) with flaky IndexedDB.
Related errors
- read
- write
- Failed to clear storage
- Failed to delete category: ${errorMessage}
- Failed to delete tag: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/bb5062fc4129c69f.
Report an issue: GitHub.