-
Notifications
You must be signed in to change notification settings - Fork 100
Add context messages to failed queries #2434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
plugins/DB.cpp
Outdated
| while (snippetByteLength > 0 && (query[snippetByteLength] & 0xc0) == 0x80) { | ||
| snippetByteLength--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use snippet offset when trimming UTF-8 tail
When sqlOffset is nonzero (i.e., the error offset was moved forward), the tail-trimming loop checks query[snippetByteLength], which indexes from the start of the original query and also uses the length rather than the last byte index. This means the UTF‑8 continuation check is applied to the wrong byte, so the snippet can still end mid‑codepoint and produce invalid UTF‑8 in the response. Clients expecting valid UTF‑8 may render garbled text or fail to decode. The check should use the end of the snippet (e.g., query[sqlOffset + snippetByteLength - 1], with bounds guards) before decrementing.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Replace any whitespace in the displayed snippet with spaces so the caret alignment is stable. | ||
| for (char& c : sqlSnippet) { | ||
| if (isspace(c)) { | ||
| c = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard isspace against non-ASCII bytes
The new whitespace-normalization loop calls isspace(c) on a char from a UTF-8 snippet. On platforms where char is signed, any byte ≥0x80 becomes negative and passing it to isspace is undefined behavior (often an out-of-bounds lookup in the ctype table). This can mis-handle or even crash when the SQL contains non-ASCII identifiers or string literals. Cast to unsigned char (or use std::isspace(static_cast<unsigned char>(c))) before calling isspace to keep UTF-8 bytes safe.
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Replace any whitespace in the displayed snippet with spaces so the caret alignment is stable. | ||
| for (char& c : sqlSnippet) { | ||
| if (isspace(c)) { | ||
| c = ' '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard isspace against signed-char UB
When the query contains non‑ASCII bytes (e.g., UTF‑8 identifiers), char may be signed on this platform, so passing it directly to isspace is undefined behavior. That can mis-handle whitespace normalization or crash while constructing the error context for otherwise valid UTF‑8 queries. Casting to unsigned char (or using a wrapper) avoids UB: isspace(static_cast<unsigned char>(c)).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this accurate/useful, @tylerkaraszewski ?
| }; | ||
|
|
||
| static Sqlite3QRFSpecWrapper parseSQLite3Args(const string& argsToParse); | ||
| static string generateErrorContextMessage(const string& query, const string& errorMessage, int errorOffset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a comment somewhere (here or in the cpp file) that it was ported over from sqlite3's shell_error_context?
Details
Implements the same context message as found here:
https://sqlite.org/src/info/55424c650715b3?ln=2545-2586
Fixed Issues
Fixes Bedrock portion of: https://github.com/Expensify/Expensify/issues/577395
There will be an auth PR that depends on this one as well.
Tests
Internal Testing Reminder: when changing bedrock, please compile auth against your new changes