Skip to content

Commit 8fe5035

Browse files
authored
🐛(sync) Dropbox exists swallows auth errors (#1394)
1 parent 8562d06 commit 8fe5035

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

packages/filesystem/dropbox/dropbox.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,20 @@ describe("DropboxFileSystem", () => {
1414

1515
await expect(fs.delete("missing.txt")).resolves.toBeUndefined();
1616
});
17+
18+
it("exists should return false on path not found", async () => {
19+
const fs = new DropboxFileSystem("/", "token");
20+
vi.spyOn(fs, "request").mockRejectedValue(
21+
new Error('Dropbox API Error: 409 - {"error_summary":"path/not_found/..."}')
22+
);
23+
24+
await expect(fs.exists("/missing.txt")).resolves.toBe(false);
25+
});
26+
27+
it("exists should rethrow auth and network errors", async () => {
28+
const fs = new DropboxFileSystem("/", "token");
29+
vi.spyOn(fs, "request").mockRejectedValue(new Error("Dropbox API Error: 401 - invalid_access_token"));
30+
31+
await expect(fs.exists("/test.txt")).rejects.toThrow("invalid_access_token");
32+
});
1733
});

packages/filesystem/dropbox/dropbox.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import type { FileInfo, FileCreateOptions, FileReader, FileWriter } from "../fil
44
import { joinPath } from "../utils";
55
import { DropboxFileReader, DropboxFileWriter } from "./rw";
66

7+
function isDropboxPathNotFound(error: unknown): boolean {
8+
const message = error instanceof Error ? error.message : String(error);
9+
return message.includes("path_lookup/not_found") || message.includes("path/not_found");
10+
}
11+
712
export default class DropboxFileSystem implements FileSystem {
813
accessToken?: string;
914

@@ -149,7 +154,7 @@ export default class DropboxFileSystem implements FileSystem {
149154
}),
150155
});
151156
} catch (e: any) {
152-
if (e.message?.includes("path_lookup/not_found") || e.message?.includes("path/not_found")) {
157+
if (isDropboxPathNotFound(e)) {
153158
return;
154159
}
155160
throw e;
@@ -241,8 +246,11 @@ export default class DropboxFileSystem implements FileSystem {
241246
}),
242247
});
243248
return true;
244-
} catch (_) {
245-
return false;
249+
} catch (e) {
250+
if (isDropboxPathNotFound(e)) {
251+
return false;
252+
}
253+
throw e;
246254
}
247255
}
248256

0 commit comments

Comments
 (0)