-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(d1): intercept and stringify errors thrown in --json mode (#4872)
* fix(d1): intercept and stringify errors thrown in --json mode * fix: add light parsing on d1 execute error message * add test * wip * implement JsonFriendlyFatalError * address PR feedback
- Loading branch information
Showing
5 changed files
with
109 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: intercept and stringify errors thrown by d1 execute in --json mode | ||
|
||
Prior to this PR, if a query threw an error when run in `wrangler d1 execute ... --json`, wrangler would swallow the error. | ||
|
||
This PR returns the error as JSON. For example, the invalid query `SELECT asdf;` now returns the following in JSON mode: | ||
|
||
```json | ||
{ | ||
"error": { | ||
"text": "A request to the Cloudflare API (/accounts/xxxx/d1/database/xxxxxxx/query) failed.", | ||
"notes": [ | ||
{ | ||
"text": "no such column: asdf at offset 7 [code: 7500]" | ||
} | ||
], | ||
"kind": "error", | ||
"name": "APIError", | ||
"code": 7500 | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters