Skip to content

Commit 8c3cdc3

Browse files
Do not report "d1 execute" command file missing error to Sentry (#9162)
1 parent 4672bda commit 8c3cdc3

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

.changeset/social-cups-roll.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+
Do not report "d1 execute" command file missing error to Sentry

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ describe("execute", () => {
142142
);
143143
});
144144

145+
it("should throw a UserError if file does not exist", async () => {
146+
setIsTTY(false);
147+
writeWranglerConfig({
148+
d1_databases: [
149+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
150+
],
151+
});
152+
153+
await expect(runWrangler(`d1 execute db --file missing.sql --local --json`))
154+
.rejects.toThrowErrorMatchingInlineSnapshot(`
155+
[Error: {
156+
"error": {
157+
"text": "Unable to read SQL text file /"missing.sql/". Please check the file path and try again."
158+
}
159+
}]
160+
`);
161+
});
162+
145163
it("should show banner by default", async () => {
146164
setIsTTY(false);
147165
writeWranglerConfig({

packages/wrangler/src/d1/execute.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,17 @@ function shorten(query: string | undefined, length: number) {
598598
}
599599

600600
async function checkForSQLiteBinary(filename: string) {
601-
const fd = await fs.open(filename, "r");
602601
const buffer = Buffer.alloc(15);
603-
await fd.read(buffer, 0, 15);
602+
603+
try {
604+
const fd = await fs.open(filename, "r");
605+
await fd.read(buffer, 0, 15);
606+
} catch (e) {
607+
throw new UserError(
608+
`Unable to read SQL text file "${filename}". Please check the file path and try again.`
609+
);
610+
}
611+
604612
if (buffer.toString("utf8") === "SQLite format 3") {
605613
throw new UserError(
606614
"Provided file is a binary SQLite database file instead of an SQL text file. The execute command can only process SQL text files. Please export an SQL file from your SQLite database and try again."

0 commit comments

Comments
 (0)