Add Structured Error Format and New Verbosity Levels in libpq#4947
Add Structured Error Format and New Verbosity Levels in libpq#4947rahim-kanji merged 5 commits intov3.0from
Conversation
…rror information: PSERRORS_FORMATTED_DEFAULT – Default formatted error message PSERRORS_FORMATTED_VERBOSE – Verbose formatted error message
Implemented a parser to handle the new format.
There was a problem hiding this comment.
Hello @rahim-kanji, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on enhancing error reporting in libpq, the PostgreSQL client library. I'm deprecating the PQgetResultFromPGconn() API and introducing a structured, length-prefixed error format for errors returned via PQerrorMessage(). Additionally, I'm adding two new error verbosity levels: PSERRORS_FORMATTED_DEFAULT and PSERRORS_FORMATTED_VERBOSE. The changes modify the Makefile to include a patch file, and update startup.c, fe-protocol3.c, libpq-fe.h, PgSQL_Connection.h, and PgSQL_Connection.cpp to implement the new error formatting and verbosity levels.
Highlights
- Deprecation:
PQgetResultFromPGconn()API is being deprecated. - Error Formatting: Introducing a structured, length-prefixed error format for
PQerrorMessage(). - New Verbosity Levels: Adding
PSERRORS_FORMATTED_DEFAULTandPSERRORS_FORMATTED_VERBOSEerror verbosity levels. - Error Handling: The pull request replaces direct calls to
set_error_from_resultwithset_error_from_PQerrorMessageinPgSQL_Connection.cppto leverage the new error formatting.
Changelog
Click here to see the changelog
- deps/Makefile
- Added
fmt_err_msg.patchto the list of patches to be applied during the build process.
- Added
- include/PgSQL_Connection.h
- Added a declaration for
set_error_from_PQerrorMessage()method. - Added declarations for
is_valid_formatted_pq_error_headerandparse_pq_error_messagemethods.
- Added a declaration for
- lib/PgSQL_Connection.cpp
- Replaced calls to
set_error_from_resultwithset_error_from_PQerrorMessageto use the new error formatting. - Implemented
set_error_from_PQerrorMessage()to parse the formatted error message fromPQerrorMessage()and populate the error information. - Implemented helper functions
is_valid_formatted_pq_error_headerandparse_pq_error_messageto parse the new error message format.
- Replaced calls to
- src/bin/psql/startup.c
- Added
formatted_defaultandformatted_verboseas valid options for theVERBOSITYsetting in psql.
- Added
- src/interfaces/libpq/fe-protocol3.c
- Implemented the logic for formatting error messages based on the
PSERRORS_FORMATTED_DEFAULTandPSERRORS_FORMATTED_VERBOSEverbosity levels. - The formatted error message includes fields like severity, SQLSTATE, and primary message, with verbose mode adding detail, hint, context, etc.
- Implemented the logic for formatting error messages based on the
- src/interfaces/libpq/libpq-fe.h
- Added
PSERRORS_FORMATTED_DEFAULTandPSERRORS_FORMATTED_VERBOSEto thePGVerbosityenum.
- Added
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Errors in the code,
A structured format now,
Verbose details bloom.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces structured error formatting and new verbosity levels in libpq, along with deprecating the PQgetResultFromPGconn() API. The changes seem well-structured and address the stated goals. However, there are a few areas that could benefit from further review and potential adjustments, as identified in the review comments.
Summary of Findings
- Error Handling Consistency: Ensure that the new
set_error_from_PQerrorMessage()function provides equivalent or better error information compared to the deprecatedPQgetResultFromPGconn()andset_error_from_result()in all scenarios. - Code Clarity and Documentation: Add comments to explain the purpose and meaning of variables like
libErrand the logic behind specific code sections, such as the integer overflow check inparse_pq_error_message. - Potential Out-of-Bounds Access: Address the potential out-of-bounds access in
is_valid_formatted_pq_error_headerby adding a check to ensuresize_endis within the string bounds before accessings[size_end].
Merge Readiness
The pull request introduces valuable improvements to error handling and verbosity in libpq. However, before merging, it's recommended to address the identified issues related to error handling consistency, code clarity, potential out-of-bounds access, and configuration flexibility. Addressing these points will improve the robustness and maintainability of the code. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the HIGH severity comment should be addressed before merging.
|
Can one of the admins verify this patch? |
6e544c4 to
7c46f6c
Compare
PQgetResultFromPGconn()API.PSERRORS_FORMATTED_DEFAULTandPSERRORS_FORMATTED_VERBOSECloses #4948