Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/filesystem/dropbox/dropbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@ describe("DropboxFileSystem", () => {

await expect(fs.delete("missing.txt")).resolves.toBeUndefined();
});

it("exists should return false on path not found", async () => {
const fs = new DropboxFileSystem("/", "token");
vi.spyOn(fs, "request").mockRejectedValue(
new Error('Dropbox API Error: 409 - {"error_summary":"path/not_found/..."}')
);

await expect(fs.exists("/missing.txt")).resolves.toBe(false);
});

it("exists should rethrow auth and network errors", async () => {
const fs = new DropboxFileSystem("/", "token");
vi.spyOn(fs, "request").mockRejectedValue(new Error("Dropbox API Error: 401 - invalid_access_token"));

await expect(fs.exists("/test.txt")).rejects.toThrow("invalid_access_token");
});
});
14 changes: 11 additions & 3 deletions packages/filesystem/dropbox/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import type { FileInfo, FileCreateOptions, FileReader, FileWriter } from "../fil
import { joinPath } from "../utils";
import { DropboxFileReader, DropboxFileWriter } from "./rw";

function isDropboxPathNotFound(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error);
return message.includes("path_lookup/not_found") || message.includes("path/not_found");
}

export default class DropboxFileSystem implements FileSystem {
accessToken?: string;

Expand Down Expand Up @@ -149,7 +154,7 @@ export default class DropboxFileSystem implements FileSystem {
}),
});
} catch (e: any) {
if (e.message?.includes("path_lookup/not_found") || e.message?.includes("path/not_found")) {
if (isDropboxPathNotFound(e)) {
return;
}
throw e;
Expand Down Expand Up @@ -241,8 +246,11 @@ export default class DropboxFileSystem implements FileSystem {
}),
});
return true;
} catch (_) {
return false;
} catch (e) {
if (isDropboxPathNotFound(e)) {
return false;
}
throw e;
}
}

Expand Down
Loading