From 7cab74dca47ff4a07432504f204a15718d935b62 Mon Sep 17 00:00:00 2001 From: rutwik2001 Date: Thu, 11 Jun 2026 15:28:07 -0700 Subject: [PATCH] fix(useFiles): stop warning on expected evicted-media reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit readFile() logged a warn on every encrypted read that returned no local bytes, conflating two cases: (1) the file is simply not on this device (evicted off-device or synced as metadata but never pulled) and (2) a genuine decrypt/IO failure. Case (1) is an expected state once media eviction + backup restore is in play, so it spammed warn on each render of restorable media. Split the outcomes: a null result (clean not-found) now logs at debug and falls through to the legacy/restore path quietly; only a thrown error (decrypt/IO) keeps the warn. Behavior is unchanged — the caller still resolves missing bytes via backup-first restore (EvictedMediaTile / downloadEvictedMedia). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/react/useFiles.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/react/useFiles.ts b/src/react/useFiles.ts index da20ed952..30bce49d8 100644 --- a/src/react/useFiles.ts +++ b/src/react/useFiles.ts @@ -572,14 +572,23 @@ export function useFiles(options: UseFilesOptions): UseFilesResult { try { const encryptionKey = await getEncryptionKey(walletAddress); const result = await readEncryptedFile(mediaId, encryptionKey); - if (!result) { - throw new Error(`File could not be found: ${mediaId}`); + if (result) { + return new File([result.blob], result.metadata?.name || mediaId, { + type: result.metadata?.type || "application/octet-stream", + }); } - return new File([result.blob], result.metadata?.name || mediaId, { - type: result.metadata?.type || "application/octet-stream", - }); + // result === null means the encrypted bytes simply aren't on this + // device: the file was evicted off-device, or synced as metadata but + // never pulled. This is an EXPECTED state once media eviction / backup + // restore is in play — the caller resolves it via backup-first restore + // (e.g. EvictedMediaTile / downloadEvictedMedia). Log at debug so it + // stays traceable without spamming warn on every evicted read. + getLogger().debug( + `[useFiles] No local encrypted bytes for ${mediaId} (likely evicted), trying legacy storage` + ); } catch (encryptedError) { - // If encrypted read fails, fall back to legacy storage + // A real failure (decrypt error, IO error) — keep it at warn so it + // surfaces, since this is not the expected "not present" path. getLogger().warn( `[useFiles] Encrypted read failed for ${mediaId}, trying legacy storage`, encryptedError