Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @eebbi, 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!
I've addressed a bug where the EventzClient was causing fatal errors in wp-admin due to unhandled exceptions during API calls. My changes modify the error handling mechanism within the EventzClient to log these issues gracefully instead of throwing exceptions. This ensures that the application remains stable even when the Eventz API returns an unexpected status, improving the overall robustness of the integration.
Highlights
- Error Handling Improvement: The
EventzClient'sdo_get_requestmethod no longer throws anEventzExceptionwhen an API call returns a non-successful status code (not 200 or 201). Instead, it now logs the error using aLoggerinstance, which prevents fatal errors in thewp-admininterface. - Method Return Value on Error: Upon encountering an error (non-200/201 status code), the
do_get_requestmethod now explicitly returnsfalseafter logging the issue, providing a clear indication of failure to the calling code.
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 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 or fill out our survey 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.
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
This pull request aims to fix a fatal error by logging API errors from EventzClient instead of throwing exceptions. While the intention is correct, the current implementation introduces a breaking change by returning false on error. This can cause new fatal errors in parts of the application that are not prepared for this return value. I've left a critical comment on lib/EventzClient.php explaining the issue and suggesting a safer architectural approach to error handling in this case.
| ( new Logger() )->error( | ||
| sprintf( '%s: %s', $api_url, $payload->body ?? 'Unknown error' ), | ||
| $status_code | ||
| [ 'status_code' => $status_code ] | ||
| ); | ||
|
|
||
| return false; |
There was a problem hiding this comment.
This change from throwing an exception to returning false is a breaking change in the function's contract. It can lead to new fatal errors in downstream code that is not prepared to handle a false value.
For example, lib/Eventz.php's admin_event_search_callback() calls $client->search_events() and then accesses $events->items. If search_events() propagates this false value, the code will crash with a "Trying to get property 'items' of non-object" fatal error.
While preventing uncaught exceptions is the right goal, this solution trades one fatal error for another. A safer approach is to handle errors inside the specific EventzClient methods (like search_events and get_item). These methods have the context to return a sensible default (e.g., an empty result set or null) that won't break their callers. I recommend handling the error in the higher-level methods of EventzClient to provide safe defaults to consumers.
Severa-ID: 2247
Severa-kuvaus: TMS-1183 Eventz-integraation korjaus puuttuvan API-avaimen osalta
Task: https://hiondigital.atlassian.net/browse/TMS-1183
Description
Log error instead of throwing the exception which causes a fatal error in wp-admin
Types of changes