AvaloniaUI/Avalonia · error · TypeError

Unable to move item to the requested directory

Error message

Unable to move item to the requested directory

What it means

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.

Source

Thrown at src/Browser/Avalonia.Browser/webapp/modules/storage/storageItem.ts:158

        return await ((item.handle as any).getDirectoryHandle(name) as Promise<any>);
    }

    public static async deleteAsync(item: StorageItem): Promise<any | null> {
        if (!item.handle) {
            return null;
        }

        await item.verifyPermissions("readwrite");

        return await ((item.handle as any).remove({ recursive: true }) as Promise<any>);
    }

    public static async moveAsync(item: StorageItem, destination: StorageItem): Promise<any | null> {
        if (!item.handle) {
            return null;
        }
        if (destination.kind !== "directory" || !destination.handle) {
            throw new TypeError("Unable to move item to the requested directory");
        }

        await item.verifyPermissions("readwrite");

        return await ((item.handle as any).move(destination /*, newName */) as Promise<any>);
    }

    private async verifyPermissions(mode: "read" | "readwrite"): Promise<void | never> {
        if (!this.handle) {
            return;
        }

        // If we are using polyfill, let it decide permissions by itself, we can't request anything in this case.
        if (!Caniuse.hasNativeFilePicker()) {
            return;
        }

        if (await this.handle.queryPermission({ mode }) === "granted") {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Verify destination.kind === 'directory' && destination.handle before moveAsync.
  2. Resolve the destination folder handle first (e.g. via getFolder).
  3. Handle browsers that don't implement FileSystemHandle.move by falling back to copy+delete.

Example fix

// before
await StorageItem.moveAsync(item, fileDestination); // fileDestination is a file

// after
if (destination.kind !== 'directory' || !destination.handle) throw new TypeError('destination must be a directory');
await StorageItem.moveAsync(item, destination);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!item.handle) { return null; }
if (destination.kind !== 'directory' || !destination.handle) {
  throw new TypeError('moveAsync destination must be a directory with a handle');
}

Type guard

function isDirectoryItem(item: StorageItem): boolean {
  return item.kind === 'directory' && !!item.handle;
}

Try / catch

try { return await StorageItem.moveAsync(item, destination); }
catch (e) {
  if (e instanceof TypeError && /move item/.test(e.message)) { /* fall back to copy+delete */ return null; }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/22337ca2fc7b7958. Report an issue: GitHub.