From 7a611ac5c5fbb287c6f0a7b7f5b0abbe0a8f1f53 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Tue, 10 Jun 2025 16:11:53 -0700 Subject: [PATCH] Chore: Web: Fix `TypeMismatchWarning` logged frequently on startup in dev mode (#12453) --- .../utils/fs-driver/fs-driver-rn.web.worker.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/app-mobile/utils/fs-driver/fs-driver-rn.web.worker.ts b/packages/app-mobile/utils/fs-driver/fs-driver-rn.web.worker.ts index b4de7a65ec..83ddd2c9b7 100644 --- a/packages/app-mobile/utils/fs-driver/fs-driver-rn.web.worker.ts +++ b/packages/app-mobile/utils/fs-driver/fs-driver-rn.web.worker.ts @@ -54,8 +54,8 @@ export interface TransferableStat { isDirectory: boolean; } -const isNotFoundError = (error: DOMException) => error.name === 'NotFoundError'; -const isTypeMismatchError = (error: DOMException) => error.name === 'TypeMismatchError'; +const isNotFoundError = (error: Error) => error instanceof DOMException && error.name === 'NotFoundError'; +const isTypeMismatchError = (error: Error) => error instanceof DOMException && error.name === 'TypeMismatchError'; const externalDirectoryPrefix = '/external/'; type AccessHandleDatabaseControl = { @@ -240,8 +240,10 @@ export class WorkerApi { handle = await parent.getDirectoryHandle(folderName, { create }); this.directoryHandleCache_.set(path, handle); } catch (error) { - // TODO: Handle this better - logger.warn('Error getting directory handle', error, 'for', path, 'create:', create); + if (!isNotFoundError(error)) { + throw error; + } + handle = null; } @@ -402,7 +404,13 @@ export class WorkerApi { public async stat(path: string, handle?: FileSystemDirectoryHandle|FileSystemFileHandle): Promise { logger.debug('stat', path, handle ? 'with handle' : ''); - handle ??= await this.pathToDirectoryHandle_(path); + try { + handle ??= await this.pathToDirectoryHandle_(path); + } catch (error) { + if (!isTypeMismatchError(error)) { + throw error; + } + } try { handle ??= await this.pathToFileHandle_(path); } catch (error) {