{"record":{"id":"22337ca2fc7b7958","repo":"AvaloniaUI/Avalonia","slug":"unable-to-move-item-to-the-requested-directory","errorCode":null,"errorMessage":"Unable to move item to the requested directory","messagePattern":"Unable to move item to the requested directory","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/Browser/Avalonia.Browser/webapp/modules/storage/storageItem.ts","lineNumber":158,"sourceCode":"        return await ((item.handle as any).getDirectoryHandle(name) as Promise<any>);\n    }\n\n    public static async deleteAsync(item: StorageItem): Promise<any | null> {\n        if (!item.handle) {\n            return null;\n        }\n\n        await item.verifyPermissions(\"readwrite\");\n\n        return await ((item.handle as any).remove({ recursive: true }) as Promise<any>);\n    }\n\n    public static async moveAsync(item: StorageItem, destination: StorageItem): Promise<any | null> {\n        if (!item.handle) {\n            return null;\n        }\n        if (destination.kind !== \"directory\" || !destination.handle) {\n            throw new TypeError(\"Unable to move item to the requested directory\");\n        }\n\n        await item.verifyPermissions(\"readwrite\");\n\n        return await ((item.handle as any).move(destination /*, newName */) as Promise<any>);\n    }\n\n    private async verifyPermissions(mode: \"read\" | \"readwrite\"): Promise<void | never> {\n        if (!this.handle) {\n            return;\n        }\n\n        // If we are using polyfill, let it decide permissions by itself, we can't request anything in this case.\n        if (!Caniuse.hasNativeFilePicker()) {\n            return;\n        }\n\n        if (await this.handle.queryPermission({ mode }) === \"granted\") {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Browser/Avalonia.Browser/webapp/modules/storage/storageItem.ts#L140-L176","documentation":"Thrown (as TypeError) by StorageItem.moveAsync when the destination item is not a directory or has no handle. The move uses FileSystemHandle.move(destination), which requires the destination to be a FileSystemDirectoryHandle; a file destination or a handleless item is invalid.","triggerScenarios":"StorageItem.moveAsync(item, destination) where destination.kind !== 'directory' or destination.handle is undefined. Also note item.handle being falsy returns null earlier, so the item itself must have a handle.","commonSituations":"Moving a file into another file instead of a folder; destination is a well-known-directory placeholder without a resolved handle; polyfill mode without a native handle; browser without native move() support.","solutions":["Verify destination.kind === 'directory' && destination.handle before moveAsync.","Resolve the destination folder handle first (e.g. via getFolder).","Handle browsers that don't implement FileSystemHandle.move by falling back to copy+delete."],"exampleFix":"// before\nawait StorageItem.moveAsync(item, fileDestination); // fileDestination is a file\n\n// after\nif (destination.kind !== 'directory' || !destination.handle) throw new TypeError('destination must be a directory');\nawait StorageItem.moveAsync(item, destination);","handlingStrategy":"type-guard","validationCode":"if (!item.handle) { return null; }\nif (destination.kind !== 'directory' || !destination.handle) {\n  throw new TypeError('moveAsync destination must be a directory with a handle');\n}","typeGuard":"function isDirectoryItem(item: StorageItem): boolean {\n  return item.kind === 'directory' && !!item.handle;\n}","tryCatchPattern":"try { return await StorageItem.moveAsync(item, destination); }\ncatch (e) {\n  if (e instanceof TypeError && /move item/.test(e.message)) { /* fall back to copy+delete */ return null; }\n  throw e;\n}","preventionTips":["Ensure the destination is a FileSystemDirectoryHandle before move.","Resolve folder handles via getFolder first.","Provide a copy+delete fallback for browsers without move()."],"tags":["browser","storage","file-system-access","typescript","validation","move"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}