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
5 changes: 5 additions & 0 deletions .changeset/cute-pets-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Improve error message when `d1 export --output` points to a directory
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ updates:
- "c3"
- "dependencies"
- "skip-pr-description-validation"
- "skip-changeset-review"

# Check for workerd & workers-types updates for Miniflare
- package-ecosystem: "npm"
Expand Down
10 changes: 10 additions & 0 deletions packages/wrangler/src/__tests__/d1/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe("export", () => {
);
});

it("should throw if output is a directory", async () => {
fs.mkdirSync("test-dir");

await expect(
runWrangler("d1 export db --output test-dir")
).rejects.toThrowError(
`Please specify a file path for --output, not a directory.`
);
});

it("should throw if local and remote are both set", async () => {
await expect(
runWrangler("d1 export db --local --remote --output test-local.sql")
Expand Down
8 changes: 8 additions & 0 deletions packages/wrangler/src/d1/export.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { statSync } from "node:fs";
import fs from "node:fs/promises";
import path from "node:path";
import { spinner, spinnerWhile } from "@cloudflare/cli/interactive";
Expand Down Expand Up @@ -82,6 +83,13 @@ export const d1ExportCommand = createCommand({
throw new UserError(`You cannot specify both --no-schema and --no-data`);
}

const stats = statSync(output, { throwIfNoEntry: false });
if (stats?.isDirectory()) {
throw new UserError(
`Please specify a file path for --output, not a directory.`
);
}

// Allow multiple --table x --table y flags or none
const tables: string[] = table
? Array.isArray(table)
Expand Down
Loading