Skip to content

Log MySQL Errors#102

Open
Lightning11wins wants to merge 128 commits into
masterfrom
log-mysql-errors
Open

Log MySQL Errors#102
Lightning11wins wants to merge 128 commits into
masterfrom
log-mysql-errors

Conversation

@Lightning11wins
Copy link
Copy Markdown
Contributor

@Lightning11wins Lightning11wins commented May 13, 2026

This PR will improve error handling in the MySQL driver by making the following changes:

  • Fix errors from mysql_query() being ignored.
  • Fix errors from mysql_store_result() being ignored.
  • Fix errors from mysql_real_escape_string() being ignored.
  • Fix "errors" pretending to be warnings.
  • Fix error-propagation failures.
  • Fix errors not being marked as resolved.
  • Fix errors being cleared when they weren't resolved.
  • Add more error messages.
  • Add expect to reduce performance hit from checking for errors.

Useful C MySQL lib docs:

Israel added 30 commits October 13, 2025 09:53
Improve edge case logic in comparison functions.
Remove unregister driver function.
Clean up exp_functions.c.
Simplify dataqa_duplicates component in preparation for making it the boundary into our new duplicate system.
Add exp functions: sparse_eql(), ln(), and logn().
Fix bugs in comparison functions.
Make minor tweaks to objdrv_cluster.c.
Modify cluster files to use string keys.
Build vectors fully sparsely.
Add ca_fprint_vector().
Add snprint_llu().
Add exp_fn_trim().
Update exp_fn_cmp().
Organize exp function definitions by group.
Add statistics tracking to cluster driver.
Reduce minimum hint threshold.
Add array handling to ci_xaToTrimmedArray().
Update timer to handle multiple starts and stops properly.
Re-add Levenshtein to exp_functions.
Publish edit_dist() in the cluster library.
Fix mistakes in cluster driver function signatures.
Fix spelling mistakes.
Add detail to an error message in the lexer.
Remove unused .cluster files.
Clean up cluster-schema.cluster.
Clean up other unused junk.
Add known issues to string similarity documentation.
Clean up and organize todos.
Clean up testing code in several files.
…ast commit).

Update tests to pass with this modification.
… caches).

Fix a formatting issue with the stat method.
Fix a missing include in the util.c library.
…le hundred bytes.

Add check_double() to handle functions that return NAN on failure.
Clean up.
…rary.

Round similarity results to avoid floating point errors.
Enable caching for memory allocated in get_cluster_size().
Rename edit_dist() to ca_edit_dist() to match format for public functions.
Rename print_diagnostics() to print_err().
Fix a possible uninitialized read.
Fix memset() not initializing data.
Improve documentation.
Modify magic functions to print errors to stderr instead of stdout.
Add explicit tree->Alloc = 0; to some exp_functions.
Add error checking.
Add consts.
Re-add typecasts that I thought were optional.
Improve comments.
Clean up.
Add some error checking.
Add expect.h to mtask.c.
Add recursion checking.
Add HAVE_BUILTIN_EXPECT to config.h.in and cxlibconfig.h.in.
Add code to include cxlibconfig.h.in from expect.h.
Add comments to explain what each .h.in file is used for.
Remove checks for __builtin_expect() from centrallix because we only need them in centrallix-lib.
Remove cflags -DHAVE_BUILTIN_EXPECT because using configs is better.
Rebuild configure files.
Fix errors from mysql_query() being ignored.
Fix errors from mysql_store_result() being ignored.
Fix errors from mysql_real_escape_string() being ignored.
Fix "errors" pretending to be warnings.
Fix error-propagation failures.
Fix errors not being marked as resolved.
Fix errors being cleared when they weren't resolved.
Fix formatting mistakes.
Add more error messages.
Add expect to reduce performance hit from checking for errors.
@Lightning11wins Lightning11wins self-assigned this May 13, 2026
@Lightning11wins Lightning11wins added ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer. labels May 13, 2026
@Lightning11wins
Copy link
Copy Markdown
Contributor Author

@greptileai Please review this PR.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR improves error visibility in the MySQL object driver by propagating previously-ignored failures from mysql_query, mysql_store_result, and mysql_real_escape_string through mssError, and refactors mssError itself from a custom format parser to vsnprintf with a void return type.

  • mssError rewrite (mtsession.c/mtsession.h): return type changed from int to void, format handling delegated to vsnprintf, session-context logging preserved; all 93 affected callers updated across the PR.
  • MySQL driver error handling (objdrv_mysql.c): mysql_query and mysql_store_result failures now log an mssError before returning MYSD_RUNQUERY_ERROR; DML NULL-result handling is correctly preserved; mysql_real_escape_string failure is now detected and reported; goto-based cleanup consolidates previously duplicated teardown code.
  • New check/check_ptr diagnostic macros (util.h/util.c): lightweight wrappers that print developer diagnostics (file, line, errno) when a function returns an unexpected value, used to surface allocation and library-init failures without changing control flow.

Confidence Score: 5/5

The changes are additive error-logging improvements; the DML NULL-result regression flagged in earlier review rounds has been fixed, and no new data-path logic was introduced.

All previously identified correctness issues were addressed in prior review rounds. The remaining findings are style-level: a dead variable, a misleading goto label, and a pointer-to-integer-literal comparison. The core control flow is correct.

centrallix/osdrivers/objdrv_mysql.c and centrallix-lib/src/mtsession.c carry the bulk of the functional change and are worth a final read-through.

Important Files Changed

Filename Overview
centrallix/osdrivers/objdrv_mysql.c Core change: adds mssError calls after previously-silent failures, fixes DML NULL-result handling, introduces goto-based cleanup, and checks mysql_real_escape_string return value. A dead variable and a misleading goto label remain; functionally the logic is correct.
centrallix-lib/src/mtsession.c mssError rewritten: return type changed from int to void, custom format parser replaced with vsnprintf into a fixed BUFSIZ buffer, session list handling preserved.
centrallix-lib/include/mtsession.h Declaration of mssError updated from int to void to match the new implementation; no other functional changes.
centrallix-lib/include/util.h Adds check/check_neg/check_ptr/check_double diagnostic macros, min/max via GCC statement expressions, Timer API, and formatting utilities; all wrapped with appropriate include guards.
centrallix-lib/src/util.c Implements the new utilities declared in util.h; all additions are additive and do not touch existing strtoi/strtoui logic.
centrallix-lib/include/expect.h Adds conditional inclusion of cxlibconfig.h so HAVE_BUILTIN_EXPECT is available; reformats existing LIKELY/UNLIKELY macros with no logic change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["mysd_internal_RunQuery_conn_va()"] --> B["Build query string\n(SafeAppend for each param)"]
    B -- "SafeAppend fails" --> ERR1["mssError(1) escape error\ngoto error"]
    B -- "Success" --> C["mysql_query()"]
    C -- "Returns != 0" --> ERR2["mssError(1) query error\ngoto query_error"]
    C -- "Returns 0" --> D["mysql_store_result()"]
    D --> E{"mysql_errno() != 0?"}
    E -- "Yes (real error)" --> ERR3["mssError(1) store error\nfree result\ngoto error"]
    E -- "No (DML = NULL is OK)" --> F["rval = query_result\ngoto cleanup"]
    ERR1 --> CLEANUP
    ERR2 --> CLEANUP["cleanup:\nif rval == ERROR\n  mssError(0) context msg\nxsDeInit(query)\nreturn rval"]
    ERR3 --> CLEANUP
    F --> CLEANUP
    CLEANUP --> G["Return MYSD_RUNQUERY_ERROR\nor valid MYSQL_RES*"]
Loading

Reviews (6): Last reviewed commit: "Remove more error messages that might co..." | Re-trigger Greptile

Comment thread centrallix/osdrivers/objdrv_mysql.c
Comment thread centrallix/osdrivers/objdrv_mysql.c
Comment thread centrallix/osdrivers/objdrv_mysql.c Outdated
Comment thread centrallix/osdrivers/objdrv_mysql.c Outdated
Comment thread centrallix/osdrivers/objdrv_mysql.c Outdated
Comment thread centrallix/osdrivers/objdrv_mysql.c
@Lightning11wins
Copy link
Copy Markdown
Contributor Author

@greptileai Please re-review this PR. Any other issues? Let me know if it looks good.

@Lightning11wins
Copy link
Copy Markdown
Contributor Author

Warning: This PR is blocked behind the following PRs. Please review them first and review this PR after they have been merged into master so that their changes will not appear in the diff for this PR.

We should rebase this branch before merging to clean up merge commit mayhem.

@Lightning11wins
Copy link
Copy Markdown
Contributor Author

This PR is ready for human review (after the blockers are resolved).

@Lightning11wins Lightning11wins requested review from gbeeley and nboard May 13, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant