Skip to content

Conversation

@tylerkaraszewski
Copy link
Contributor

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

 VM  ➜  Bedrock git:(tyler-syntax-error-context) ✗ nc localhost 8888
Query
Query: SELECT notAColumn FROM jobs WHERE name = 'asfdadf';

402 Bad query
commitCount: 89526
error: no such column: notAColumn
nodeName: bedrock
peekTime: 3296
totalTime: 5955
unaccountedTime: 2656
Content-Length: 102

no such column: notAColumn
SELECT notAColumn FROM jobs WHERE name = 'asfdadf';
       ^--- error here


Internal Testing Reminder: when changing bedrock, please compile auth against your new changes

@tylerkaraszewski tylerkaraszewski requested a review from a team December 31, 2025 20:04
@tylerkaraszewski tylerkaraszewski self-assigned this Dec 31, 2025
@melvin-bot melvin-bot bot requested review from carlosmiceli and removed request for a team December 31, 2025 20:05
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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
Comment on lines 349 to 350
while (snippetByteLength > 0 && (query[snippetByteLength] & 0xc0) == 0x80) {
snippetByteLength--;

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@tylerkaraszewski
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines +355 to +358
// Replace any whitespace in the displayed snippet with spaces so the caret alignment is stable.
for (char& c : sqlSnippet) {
if (isspace(c)) {
c = ' ';

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@tylerkaraszewski
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines +355 to +358
// Replace any whitespace in the displayed snippet with spaces so the caret alignment is stable.
for (char& c : sqlSnippet) {
if (isspace(c)) {
c = ' ';

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Contributor

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 ?

carlosmiceli
carlosmiceli previously approved these changes Dec 31, 2025
@carlosmiceli carlosmiceli self-requested a review December 31, 2025 21:33
@carlosmiceli carlosmiceli dismissed their stale review December 31, 2025 21:33

I approved by accident.

};

static Sqlite3QRFSpecWrapper parseSQLite3Args(const string& argsToParse);
static string generateErrorContextMessage(const string& query, const string& errorMessage, int errorOffset);
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants