Skip to content

TMS-1183: Use Logger for EventzClient errors#541

Merged
eebbi merged 1 commit intomasterfrom
TMS-1183
Aug 11, 2025
Merged

TMS-1183: Use Logger for EventzClient errors#541
eebbi merged 1 commit intomasterfrom
TMS-1183

Conversation

@eebbi
Copy link
Contributor

@eebbi eebbi commented Aug 6, 2025

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@eebbi eebbi requested a review from a team August 6, 2025 11:22
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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's do_get_request method no longer throws an EventzException when an API call returns a non-successful status code (not 200 or 201). Instead, it now logs the error using a Logger instance, which prevents fatal errors in the wp-admin interface.
  • Method Return Value on Error: Upon encountering an error (non-200/201 status code), the do_get_request method now explicitly returns false after 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +319 to +324
( new Logger() )->error(
sprintf( '%s: %s', $api_url, $payload->body ?? 'Unknown error' ),
$status_code
[ 'status_code' => $status_code ]
);

return false;

Choose a reason for hiding this comment

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

critical

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.

@vloy vloy self-assigned this Aug 7, 2025
Copy link

@vloy vloy left a comment

Choose a reason for hiding this comment

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

@eebbi eebbi merged commit 0f1c05e into master Aug 11, 2025
3 of 5 checks passed
@eebbi eebbi deleted the TMS-1183 branch August 11, 2025 09:41
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.

2 participants