diff --git a/.changeset/cute-pets-fry.md b/.changeset/cute-pets-fry.md new file mode 100644 index 000000000000..18c12e3519a2 --- /dev/null +++ b/.changeset/cute-pets-fry.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Added friendly error message when D1 export output is a directory diff --git a/packages/wrangler/src/d1/export.ts b/packages/wrangler/src/d1/export.ts index af52c2e0b612..bd8c1fdfb999 100644 --- a/packages/wrangler/src/d1/export.ts +++ b/packages/wrangler/src/d1/export.ts @@ -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.` + ); + } + } catch (e) { + if (e instanceof UserError) { + throw e; + } + } + // Allow multiple --table x --table y flags or none const tables: string[] = table ? Array.isArray(table) @@ -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");