{"record":{"id":"d74a045b1174c298","repo":"linshenkx/prompt-optimizer","slug":"category-not-found-id","errorCode":null,"errorMessage":"Category not found: ${id}","messagePattern":"Category not found: (.+?)","errorType":"exception","errorClass":"FavoriteCategoryNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":697,"sourceCode":"      });\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;\n      });\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 update category: ${errorMessage}`);\n    }\n  }\n","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L679-L715","documentation":"FavoriteCategoryNotFoundError thrown by updateCategory when no category with the given id exists in storage. The id-based lookup happens inside the storage update callback, so stale ids always fail with this error.","triggerScenarios":"Calling updateCategory('cat-123', {...}) after that category was deleted; using an id from a different device/export; race where another tab deleted the category between fetch and update.","commonSituations":"Stale UI state referencing a deleted category; multi-tab sync where one tab deletes a category another tab is editing; ids from an older import format.","solutions":["Refresh categories via getCategories() and use a current id","Handle FavoriteCategoryNotFoundError in the UI by re-syncing or dropping the stale reference","Guard multi-tab scenarios by re-validating id right before the update"],"exampleFix":"// before\nawait manager.updateCategory(staleId, { name: 'New' });\n\n// after\nconst cats = await manager.getCategories();\nif (cats.some(c => c.id === staleId)) {\n  await manager.updateCategory(staleId, { name: 'New' });\n} else {\n  // re-sync UI state\n}","handlingStrategy":"validation","validationCode":"const exists = (await manager.getCategories()).some(c => c.id === id);\nif (exists) await manager.updateCategory(id, updates);","typeGuard":"const isCategoryNotFound = (e: unknown): e is FavoriteCategoryNotFoundError => e instanceof FavoriteCategoryNotFoundError;","tryCatchPattern":"try { await manager.updateCategory(id, updates); } catch (e) { if (isCategoryNotFound(e)) { /* refresh UI state */ } throw e; }","preventionTips":["Always derive category ids from a fresh getCategories() call","Re-validate ids in multi-tab apps before mutation"],"tags":["favorites","not-found","category","stale-id"],"backgroundTag":"entity-not-found","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}