{"record":{"id":"3ed75ab9a606d53e","repo":"linshenkx/prompt-optimizer","slug":"failed-to-import-favorites-errormessage","errorCode":null,"errorMessage":"Failed to import favorites: ${errorMessage}","messagePattern":"Failed to import favorites: (.+?)","errorType":"exception","errorClass":"FavoriteImportExportError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/favorite/manager.ts","lineNumber":1445,"sourceCode":"            result.imported++;\n          } catch (error) {\n            const errorMessage = error instanceof Error ? error.message : String(error);\n            result.errors.push(`Failed to import favorite: ${errorMessage}`);\n          }\n        });\n\n        assertFavoritesPayloadWithinBudget(favoritesList, {\n          warnOnSoftLimit: true,\n        });\n\n        return favoritesList;\n      });\n\n      await this.updateStats();\n      return result;\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new FavoriteImportExportError(\n        `Failed to import favorites: ${errorMessage}`,\n        error instanceof Error ? error : undefined,\n        result.errors.length > 0 ? result.errors : undefined\n      );\n    }\n  }\n}\n","sourceCodeStart":1427,"sourceCodeEnd":1453,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/favorite/manager.ts#L1427-L1453","documentation":"Catch-all wrapper around importFavorites: any error escaping the try block (invalid JSON from JSON.parse, the validation errors above, or storage failures during save) is rethrown as FavoriteImportExportError with the original error as cause and any accumulated result.errors list attached.","triggerScenarios":"Any failure during importFavorites — malformed JSON string, missing favorites array, invalid entry content or modes, or a storage write error — bubbles up wrapped in this error.","commonSituations":"Debugging failed imports: the real reason is in the message suffix and the cause error; this wrapper only adds context and any per-entry errors collected so far.","solutions":["Read the message suffix and error.cause to identify the actual underlying failure, then fix that root cause","If the error carries accumulated per-entry errors (third constructor argument), review them for partially processed entries","Pre-validate the payload (shape, content, modes) before calling importFavorites to avoid the wrapper entirely"],"exampleFix":"// before\nawait manager.importFavorites(data);\n\n// after\ntry {\n  await manager.importFavorites(data);\n} catch (e) {\n  if (e instanceof FavoriteImportExportError) {\n    console.error('import failed:', e.message, 'cause:', e.cause);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isFavoriteImportExportError = (e: unknown): e is FavoriteImportExportError =>\n  e instanceof Error && e.name === 'FavoriteImportExportError';","tryCatchPattern":"try {\n  const result = await manager.importFavorites(data);\n} catch (e) {\n  if (isFavoriteImportExportError(e)) {\n    const root = e.cause ?? e;\n    const itemErrors = (e as any).errors ?? [];\n    // report root cause and per-entry errors, then retry with cleaned data\n  } else throw e;\n}","preventionTips":["Pre-validate the import payload (shape, content, modes) before calling importFavorites","Log e.cause to find the true underlying error","Keep exports and imports on the same library version"],"tags":["import","favorites","wrapper","error-handling"],"backgroundTag":"data-import-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}