ThrowError() method obscurs useful error messages

Created on 23 July 2025, 13 days ago

Problem/Motivation

The code in ai_provider_google_vertex/src/Plugin/AiProvider/VertexProvider.php::throwError() assumes that any output from $e->getMessage() is json encoded. If it is not, the message is discarded and the generic error message "Unknown Error: Could not get a response from the model." is thrown instead.

Steps to reproduce

Follow the instructions to set up the Provider. On the Google side, do not associate the Google Service with a billing address. Attempt to use the Drupal AI module to trigger a chat message.

The attempt will trigger an error response from the AI endpoint that the action requires billing to be set up, but all that gets logged is "Unknown Error: Could not get a response from the model."

Proposed resolution

The ProviderProxy contains code that makes decisions about whether to show the error to the user or not based on the exception returned, and ensures that the message is logged regardless.

If the error is not a JSON string that contains the CONSUMER_INVALID flag, either its reason parameter (if it is a JSON string) or the original message should be return as a AiResponseErrorException. If the error is because of a CONSUMER_INVALID error, it should probably be returned as a AiResponseErrorException rather than a Bad Request one: there is no guarantee at the point the error is thrown that it is because of a bad request - the one detailed in the steps to reproduce would be an issue with the Google Service configuration, for example. Providing the actual error with an appropriate type may allow easier debugging of any issues.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇬🇧United Kingdom MrDaleSmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @MrDaleSmith
  • @mrdalesmith opened merge request.
  • 🇬🇧United Kingdom MrDaleSmith

    Ensured that messages thrown during the AIProvider's running are passed up the tree to the error handling within the core AI module.

Production build 0.71.5 2024