Skip to content

Commit 47944d1

Browse files
fix(wrangler): show friendly error when D1 export output is a directory (#12065)
Co-authored-by: Edmund Hung <me@edmund.dev>
1 parent 12afd80 commit 47944d1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.changeset/cute-pets-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Improve error message when `d1 export --output` points to a directory

packages/wrangler/src/__tests__/d1/export.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ describe("export", () => {
2424
);
2525
});
2626

27+
it("should throw if output is a directory", async () => {
28+
fs.mkdirSync("test-dir");
29+
30+
await expect(
31+
runWrangler("d1 export db --output test-dir")
32+
).rejects.toThrowError(
33+
`Please specify a file path for --output, not a directory.`
34+
);
35+
});
36+
2737
it("should throw if local and remote are both set", async () => {
2838
await expect(
2939
runWrangler("d1 export db --local --remote --output test-local.sql")

packages/wrangler/src/d1/export.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { statSync } from "node:fs";
12
import fs from "node:fs/promises";
23
import path from "node:path";
34
import { spinner, spinnerWhile } from "@cloudflare/cli/interactive";
@@ -82,6 +83,13 @@ export const d1ExportCommand = createCommand({
8283
throw new UserError(`You cannot specify both --no-schema and --no-data`);
8384
}
8485

86+
const stats = statSync(output, { throwIfNoEntry: false });
87+
if (stats?.isDirectory()) {
88+
throw new UserError(
89+
`Please specify a file path for --output, not a directory.`
90+
);
91+
}
92+
8593
// Allow multiple --table x --table y flags or none
8694
const tables: string[] = table
8795
? Array.isArray(table)

0 commit comments

Comments
 (0)