From 428291905cd39a61fb34709b857a073b08ebea49 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:30:55 +0800 Subject: [PATCH] refactor(shares): remove unreachable throw and unused lastError clean up unreachable throw lastError and unused variable in createShareRecord while keeping retry behavior unchanged. Checkpoint: EBzJMViQJbo82zKGSakWB --- worker/src/db/queries/shares.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/worker/src/db/queries/shares.ts b/worker/src/db/queries/shares.ts index 9cdfead..8202a21 100644 --- a/worker/src/db/queries/shares.ts +++ b/worker/src/db/queries/shares.ts @@ -100,9 +100,8 @@ export async function createShareRecord( // 3. 生成令牌与哈希(唯一冲突重试最多 3 次) const MAX_RETRIES = 3 - let lastError: unknown = null - for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) { + for (let attempt = 0; ; attempt++) { const token = generateShareToken() const tokenHash = await sha256Hex(token) const id = crypto.randomUUID() @@ -125,7 +124,6 @@ export async function createShareRecord( expiresAt: shareExpiresAt } } catch (err) { - lastError = err const message = err instanceof Error ? err.message @@ -133,13 +131,11 @@ export async function createShareRecord( ? String((err as any).message) : String(err) const isConflict = /unique/i.test(message) || /constraint/i.test(message) - if (!isConflict || attempt === MAX_RETRIES) { + if (!isConflict || attempt >= MAX_RETRIES) { throw err } } } - - throw lastError } export async function listSharesByFile(