linshenkx/prompt-optimizer · error · FavoriteValidationError
Import data contains favorite with empty content
Error message
Import data contains favorite with empty content
What it means
During importFavorites, every entry in importData.favorites must be a truthy object whose content is a non-empty trimmed string. The check runs inside a per-favorite forEach try block; entries failing it throw FavoriteValidationError.
Source
Thrown at packages/core/src/services/favorite/manager.ts:1342
}
const trimmed = content.trim();
return trimmed.length > 50 ? `${trimmed.slice(0, 50)}...` : trimmed;
};
const normalizeMetadata = (metadata: unknown) => {
if (metadata && typeof metadata === 'object') {
assertFavoriteMetadataHasNoInlineImages(metadata);
return metadata as Record<string, unknown>;
}
return undefined;
};
const favoritesToImport = Array.isArray(importData.favorites) ? importData.favorites : [];
favoritesToImport.forEach((favorite: any) => {
try {
if (!favorite || typeof favorite.content !== 'string' || !favorite.content.trim()) {
throw new FavoriteValidationError('Import data contains favorite with empty content');
}
const functionMode = favorite.functionMode || 'basic';
const optimizationMode =
favorite.optimizationMode ||
(functionMode !== 'image' ? 'system' : undefined);
const imageSubMode =
favorite.imageSubMode ||
(functionMode === 'image' ? 'text2image' : undefined);
const mapping = { functionMode, optimizationMode, imageSubMode };
if (!TypeMapper.validateMapping(mapping)) {
throw new FavoriteValidationError(
`Invalid function mode in import data: functionMode=${functionMode}, optimizationMode=${optimizationMode}, imageSubMode=${imageSubMode}`
);
}
const category = categoryMapping[favorite.category] || favorite.category;View on GitHub (pinned to 3e677b1d9f)
Solutions
- Filter the favorites array before import, keeping only entries with non-empty string content
- Map your source field (text/prompt/value) to content when converting foreign data
- Regenerate the export from a known-good source if the file is corrupted
Example fix
// before
const data = JSON.stringify({ favorites: [{ content: ' ' }, null] });
await manager.importFavorites(data);
// after
const parsed = JSON.parse(data);
parsed.favorites = parsed.favorites.filter(f => f && typeof f.content === 'string' && f.content.trim());
await manager.importFavorites(JSON.stringify(parsed)); Defensive patterns
Strategy: validation
Validate before calling
const parsed = JSON.parse(data); parsed.favorites = (parsed.favorites || []).filter( (f: any) => f && typeof f?.content === 'string' && f.content.trim().length > 0 );
Type guard
const hasValidContent = (f: unknown): f is { content: string } =>
typeof f === 'object' && f !== null &&
typeof (f as any).content === 'string' && (f as any).content.trim().length > 0; Try / catch
try {
await manager.importFavorites(data);
} catch (e) {
if (e instanceof FavoriteValidationError && /empty content/.test(e.message)) {
// filter out empty-content entries and retry the import
}
} Prevention
- Filter empty-content entries from the import array up front
- Map foreign field names (text/prompt) to content when converting
- Never hand-craft import arrays without validating content
When it happens
Trigger: Importing a favorites array containing null entries, entries without a content field, non-string content (e.g. number), or whitespace-only content.
Common situations: Hand-edited or truncated exports, data from third-party tools using different field names (text/prompt instead of content), or partially corrupted export files.
Related errors
- Invalid import data format
- Favorite prompt content cannot be empty
- Cannot delete the last prompt asset version
- Cannot delete the current prompt asset version
- Category already exists: ${category.name}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/ef21e49fb3e3779b.
Report an issue: GitHub.