linshenkx/prompt-optimizer · error · FavoriteImportExportError
Failed to import favorites
Error message
Failed to import favorites: ${errorMessage} What it means
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.
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
Example fix
// before
await manager.importFavorites(data);
// after
try {
await manager.importFavorites(data);
} catch (e) {
if (e instanceof FavoriteImportExportError) {
console.error('import failed:', e.message, 'cause:', e.cause);
}
} Defensive patterns
Strategy: try-catch
Type guard
const isFavoriteImportExportError = (e: unknown): e is FavoriteImportExportError => e instanceof Error && e.name === 'FavoriteImportExportError';
Try / catch
try {
const result = await manager.importFavorites(data);
} catch (e) {
if (isFavoriteImportExportError(e)) {
const root = e.cause ?? e;
const itemErrors = (e as any).errors ?? [];
// report root cause and per-entry errors, then retry with cleaned data
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to add category
- Failed to get category usage
- Import data contains favorite with empty content
- Invalid import data format
- app backup package is missing favorites.json
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/3ed75ab9a606d53e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/core/src/services/favorite/manager.ts:1445
result.imported++;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
result.errors.push(`Failed to import favorite: ${errorMessage}`);
}
});
assertFavoritesPayloadWithinBudget(favoritesList, {
warnOnSoftLimit: true,
});
return favoritesList;
});
await this.updateStats();
return result;
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new FavoriteImportExportError(
`Failed to import favorites: ${errorMessage}`,
error instanceof Error ? error : undefined,
result.errors.length > 0 ? result.errors : undefined
);
}
}
}
View on GitHub (pinned to 3e677b1d9f)