Skip to content
Open
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
---

Added friendly error message when D1 export output is a directory
15 changes: 14 additions & 1 deletion packages/wrangler/src/d1/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export const d1ExportCommand = createCommand({
throw new UserError(`You cannot specify both --no-schema and --no-data`);
}

try {
const stats = await fs.stat(output);
if (stats.isDirectory()) {
throw new UserError(
`Please specify a file path for --output, not a directory.`
);
Comment on lines +85 to +90
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are existing automated tests for wrangler d1 export (e.g. packages/wrangler/src/__tests__/d1/export.test.ts), so this new directory-validation behavior should be covered with a test (create a directory, pass it as --output, and assert the friendly UserError message).

Copilot uses AI. Check for mistakes.
}
} catch (e) {
if (e instanceof UserError) {
throw e;
}
}

// Allow multiple --table x --table y flags or none
const tables: string[] = table
? Array.isArray(table)
Expand Down Expand Up @@ -114,7 +127,7 @@ async function exportLocal(

const id = localDB.previewDatabaseUuid ?? localDB.uuid;

// TODO: should we allow customising persistence path?
// TODO: should we allow customizing persistence path?
// Should it be --persist-to for consistency (even though this isn't persisting anything)?
const persistencePath = getLocalPersistencePath(undefined, config);
const d1Persist = path.join(persistencePath, "v3", "d1");
Expand Down