{"record":{"id":"8c3f77ac6aeae997","repo":"linshenkx/prompt-optimizer","slug":"failed-to-add-category-errormessage","errorCode":null,"errorMessage":"Failed to add category: ${errorMessage}","messagePattern":"Failed to add category: (.+?)","errorType":"exception","errorClass":"FavoriteStorageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":687,"sourceCode":"\n    try {\n      await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {\n        const categoriesList = categories || [];\n        // 检查是否已存在同名分类\n        const existing = categoriesList.find(c => c.name === category.name);\n        if (existing) {\n          throw new FavoriteValidationError(`Category already exists: ${category.name}`);\n        }\n        return [...categoriesList, newCategory];\n      });\n\n      return id;\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 add category: ${errorMessage}`);\n    }\n  }\n\n  async updateCategory(id: string, updates: Partial<FavoriteCategory>): Promise<void> {\n    try {\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        categoriesList[index] = {\n          ...categoriesList[index],\n          ...updates\n        };\n\n        return categoriesList;","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L669-L705","documentation":"Generic storage-layer wrapper thrown by FavoriteManager.addCategory when the underlying storageProvider.updateData call fails for a non-FavoriteError reason (I/O failure, serialization error, quota exceeded, provider misconfiguration).","triggerScenarios":"Storage provider throws (disk write failure, localStorage quota exceeded, IndexedDB unavailable), or the update callback throws a non-FavoriteError; called directly or via ensureDefaultCategories/importFavorites.","commonSituations":"Browser private mode with blocked storage; full localStorage quota after large imports; a custom storage provider that doesn't implement updateData correctly; storage schema corruption.","solutions":["Inspect error.cause/original message to identify the real storage failure","Free up storage or increase quota (clear old data, reduce export size)","Verify the storage provider is properly initialized and accessible before manager operations","If corruption is suspected, export favorites, reset storage, and re-import"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;","tryCatchPattern":"try { await manager.addCategory(cat); } catch (e) { if (e instanceof FavoriteStorageError) { /* inspect e.cause, surface storage issue */ } throw e; }","preventionTips":["Check storage availability before bulk operations","Monitor storage quota during imports"],"tags":["storage","io","favorites","wrapper"],"backgroundTag":"storage-write-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}