linshenkx/prompt-optimizer · warning · FavoriteValidationError

VALIDATION_ERROR

VALIDATION_ERROR

Error message

${error.message}

What it means

Main process returned VALIDATION_ERROR; converted to FavoriteValidationError with the main-process message. Input failed validation rules enforced on the Electron side.

Source

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

      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')
      }
      // 标签相关错误
      if (error.code === 'TAG_ALREADY_EXISTS') {
        throw new FavoriteTagAlreadyExistsError(error.tag || '');
      }
      if (error.code === 'TAG_NOT_FOUND') {
        throw new FavoriteTagNotFoundError(error.tag || '');
      }
      if (error.code === 'TAG_ERROR') {
        throw new FavoriteTagError(FAVORITE_ERROR_CODES.TAG_ERROR, error.message || '', { details: error.message || '' });
      }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Log and display the error.message — it states which rule failed
  2. Mirror the main-process validation rules in the renderer form
  3. Update renderer and main to the same package version so validation rules match
  4. Sanitize imported data before passing it to addFavorite

Example fix

// before
await mgr.addFavorite(raw);
// after
if (!raw.content?.trim()) throw new Error('content required');
await mgr.addFavorite(raw);
Defensive patterns

Strategy: validation

Validate before calling

function validateFavoriteInput(f: Partial<FavoritePrompt>): string[] {
  const errs: string[] = [];
  if (!f.content?.trim()) errs.push('content required');
  if (!f.functionMode) errs.push('functionMode required');
  return errs;
}

Type guard

const isFavoriteValidation = (e: unknown): e is FavoriteValidationError => e instanceof FavoriteValidationError;

Try / catch

try { await mgr.addFavorite(fav); } catch (e) { if (isFavoriteValidation(e)) { showFormError(e.message); return; } throw e; }

Prevention

When it happens

Trigger: Submitting a favorite payload that fails main-process validation (empty fields, bad enums, oversized metadata) through any proxy method.

Common situations: Renderer-side validation skipped or out of sync with stricter main-process rules; version skew between renderer and main; malformed imported data passed through directly.

Related errors


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