{"record":{"id":"cd4b1994c133d590","repo":"linshenkx/prompt-optimizer","slug":"failed-to-delete-category-errormessage","errorCode":null,"errorMessage":"Failed to delete category: ${errorMessage}","messagePattern":"Failed to delete category: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":756,"sourceCode":"\n      // ✅ 删除分类\n      await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {\n        const categoriesList = categories || [];\n        const index = categoriesList.findIndex(c => c.id === id);\n        if (index === -1) {\n          throw new FavoriteCategoryNotFoundError(id);\n        }\n\n        return categoriesList.filter(c => c.id !== id);\n      });\n\n      return favoritesInCategory.length;\n    } catch (error) {\n      if (error instanceof FavoriteError) {\n        throw error;\n      }\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to delete category: ${errorMessage}`);\n    }\n  }\n\n  async getStats(): Promise<FavoriteStats> {\n    try {\n      const stats = await this.storageProvider.getItem(this.STORAGE_KEYS.STATS);\n      if (stats) {\n        return JSON.parse(stats);\n      }\n\n      // 如果没有缓存的统计数据，计算并缓存\n      return await this.updateStats();\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to get statistics: ${errorMessage}`);\n    }\n  }\n","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L738-L774","documentation":"Generic storage wrapper thrown by deleteCategory when any non-FavoriteError failure occurs during the multi-step delete (clearing favorites' category field, then removing the category).","triggerScenarios":"Either updateData call fails (quota, I/O, provider error) during deletion; partial failure can occur after favorites were already unlinked.","commonSituations":"Storage failures mid-operation; provider timeouts; interrupted mobile app storage calls.","solutions":["Check the wrapped message for the failing step","Verify storage state consistency afterwards (favorites vs categories) and repair if partial","Retry the delete after confirming the category still exists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { await manager.deleteCategory(id); } catch (e) { if (isFavoriteStorageError(e)) { /* verify favorites/categories consistency, then recover */ } throw e; }","preventionTips":["After failed deletes, verify data consistency before retrying","Log the wrapped cause for diagnosis"],"tags":["storage","io","favorites","delete"],"backgroundTag":"storage-write-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}