{"record":{"id":"f9503bf2c599b09b","repo":"linshenkx/prompt-optimizer","slug":"category-id-list-cannot-be-empty","errorCode":null,"errorMessage":"Category ID list cannot be empty","messagePattern":"Category ID list cannot be empty","errorType":"validation","errorClass":"FavoriteValidationError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":1148,"sourceCode":"            favorite.updatedAt = Date.now();\n            affectedCount++;\n          }\n        });\n\n        return favoritesList;\n      });\n\n      await this.updateStats();\n      return affectedCount;\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteStorageError(`Failed to delete tag: ${errorMessage}`);\n    }\n  }\n\n  async reorderCategories(categoryIds: string[]): Promise<void> {\n    if (!categoryIds || categoryIds.length === 0) {\n      throw new FavoriteValidationError('Category ID list cannot be empty');\n    }\n\n    try {\n      await this.storageProvider.updateData(this.STORAGE_KEYS.CATEGORIES, (categories: FavoriteCategory[] | null) => {\n        const categoriesList = categories || [];\n\n        // 创建ID到分类的映射\n        const categoryMap = new Map<string, FavoriteCategory>();\n        categoriesList.forEach(cat => categoryMap.set(cat.id, cat));\n\n        // 按提供的ID顺序重新排序,并更新sortOrder\n        const reorderedCategories: FavoriteCategory[] = [];\n        categoryIds.forEach((id, index) => {\n          const category = categoryMap.get(id);\n          if (category) {\n            reorderedCategories.push({\n              ...category,\n              sortOrder: index","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L1130-L1166","documentation":"FavoriteValidationError thrown by reorderCategories when the categoryIds argument is null, undefined, or an empty array. Reordering requires at least one id.","triggerScenarios":"Calling reorderCategories([]) or reorderCategories(null), e.g. persisting drag-and-drop order when no categories exist.","commonSituations":"Empty category list UI saving order on teardown; programmatic reorder with unfiltered id lists.","solutions":["Skip the reorder call when the list is empty","Guard persistence of drag-drop order on categories.length > 0"],"exampleFix":"// before\nawait manager.reorderCategories(ids);\n\n// after\nif (ids.length > 0) {\n  await manager.reorderCategories(ids);\n}","handlingStrategy":"validation","validationCode":"if (categoryIds?.length) await manager.reorderCategories(categoryIds);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip order persistence when the category list is empty"],"tags":["validation","category","reorder","favorites"],"backgroundTag":"empty-input-validation","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}