linshenkx/prompt-optimizer · error · FavoriteNotFoundError

FAVORITE_NOT_FOUND

FAVORITE_NOT_FOUND

Error message

${error.id}

What it means

The Electron main process returned an IPC error with code FAVORITE_NOT_FOUND; the renderer proxy converts it to FavoriteNotFoundError carrying the favorite id. It means no favorite prompt with that id exists in storage (or it was deleted).

Solutions

  1. Refresh the favorites list and retry with a current id
  2. Catch FavoriteNotFoundError and remove the stale entry from UI state
  3. Verify the id is passed unchanged (no trimming/encoding issues)
  4. Check the favorite wasn't deleted by sync/import in another process

Example fix

// before
await favoriteManager.getFavorite(id);
// after
try { return await favoriteManager.getFavorite(id); }
catch (e) { if (e instanceof FavoriteNotFoundError) return null; throw e; }
Defensive patterns

Strategy: try-catch

Validate before calling

const exists = (await mgr.getFavorites()).some(f => f.id === id);

Type guard

const isFavoriteNotFound = (e: unknown): e is FavoriteNotFoundError => e instanceof FavoriteNotFoundError;

Try / catch

try { return await mgr.getFavorite(id); } catch (e) { if (isFavoriteNotFound(e)) return null; throw e; }

Prevention

When it happens

Trigger: Calling getFavorite/updateFavorite/setFavoritePromptAssetCurrentVersion/deleteFavoritePromptAssetVersion with a stale or nonexistent favorite id via the Electron proxy.

Common situations: UI holding a cached id after the favorite was removed on another window/device; deleted favorite still open in an editor; race between list refresh and delete; id typo or truncated id.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/3b60410d689cce48. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/src/services/favorite/electron-proxy.ts:53

        'Electron API not available. Please ensure preload script is loaded and window.electronAPI.favoriteManager is accessible.',
      );
    }
  }

  private async invokeMethod<T>(method: string, ...args: any[]): Promise<T> {
    this.ensureApiAvailable();
    try {
      const safeArgs = safeSerializeArgs(...args);
      return await (window.electronAPI.favoriteManager as any)[method](...safeArgs);
    } catch (error: any) {
      // New i18n-style structured errors: pass through as-is so UI can translate via `code + params`.
      if (typeof error?.code === 'string' && error.code.startsWith('error.')) {
        throw toErrorWithCode(error)
      }

      // 将IPC错误转换为具体的错误类型
      if (error.code === 'FAVORITE_NOT_FOUND') {
        throw new FavoriteNotFoundError(error.id || '');
      }
      if (error.code === 'FAVORITE_ALREADY_EXISTS') {
        throw new FavoriteAlreadyExistsError(error.content || '');
      }
      if (error.code === 'CATEGORY_NOT_FOUND') {
        throw new FavoriteCategoryNotFoundError(error.id || '');
      }
      if (error.code === 'VALIDATION_ERROR') {
        throw new FavoriteValidationError(error.message || '');
      }
      if (error.code === 'STORAGE_ERROR') {
        throw new FavoriteStorageError(error.message || '');
      }
      // Legacy: category already exists
      if (error.code === 'CATEGORY_ALREADY_EXISTS') {
        throw new FavoriteValidationError(error.message || 'Category already exists')
      }
      // 标签相关错误

View on GitHub (pinned to 3e677b1d9f)