linshenkx/prompt-optimizer · error · FavoriteStorageError

Failed to rename tag: ${errorMessage}

Error message

Failed to rename tag: ${errorMessage}

What it means

FavoriteStorageError thrown by renameTag when any step of the rename (updating the tag library, rewriting favorites' tag arrays, or updateStats) fails with a non-FavoriteError.

Source

Thrown at packages/core/src/services/favorite/manager.ts:1036

          // 添加新标签(如果不存在)
          const hasNewTag = tagsList.some(t => t.tag === newTag);
          if (!hasNewTag) {
            tagsList.push({
              tag: newTag,
              createdAt: Date.now()
            });
          }

          return tagsList;
        });
      }

      await this.updateStats();
      return affectedCount;
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : String(error);
      throw new FavoriteStorageError(`Failed to rename tag: ${errorMessage}`);
    }
  }

  async mergeTags(sourceTags: string[], targetTag: string): Promise<number> {
    if (!sourceTags || sourceTags.length === 0) {
      throw new FavoriteValidationError('Source tag list cannot be empty');
    }

    if (!targetTag) {
      throw new FavoriteValidationError('Target tag cannot be empty');
    }

    let affectedCount = 0;

    try {
      // 1. 更新独立标签库:删除所有源标签,确保目标标签存在
      await this.storageProvider.updateData(this.STORAGE_KEYS.TAGS, (tags: FavoriteTag[] | null) => {
        const tagsList = tags || [];

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Check the wrapped message to identify which write failed
  2. Verify favorite records' tags fields are arrays of strings
  3. Retry after freeing storage; use updateStats sparingly to avoid extra writes
Defensive patterns

Strategy: try-catch

Type guard

const isFavoriteStorageError = (e: unknown): e is FavoriteStorageError => e instanceof FavoriteStorageError;

Try / catch

try { return await manager.renameTag(oldTag, newTag); } catch (e) { if (isFavoriteStorageError(e)) { /* verify tag library consistency before retry */ } throw e; }

Prevention

When it happens

Trigger: Any updateData/put failure during the multi-write rename; favorites containing malformed tag arrays causing the rewrite to throw.

Common situations: Quota exceeded while rewriting many favorites; storage provider failures mid-rename; corrupted favorite records.

Related errors


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