Skip to content

Tidy up how API error messages are built - #25817

Merged
chippison merged 4 commits into
5.x-devfrom
api-error-message-rewrite-5x
Dec 1, 2026
Merged

chippison merged 4 commits into
5.x-devfrom
api-error-message-rewrite-5x

Conversation

@chippison

@chippison chippison commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

DEV-21093

Error responses that print no backtrace (API responses and report loading errors) now build their message in one helper, ExceptionHandler::getMessageForResponse(), instead of going through the log text processor. The safe mode output passes its backtrace through redactForDebugOutput() like other backtraces do.

Log records are rewritten the same way as these responses: the token, the salt, the root path and the database account in its 'user'@'host' form. They go through redactForDisplay() and no longer have the configured credentials replaced, because log entries are shown in notifications and in the log viewer. The error output of development mode, PIWIK_PRINT_ERROR_BACKTRACE and the command line keeps the existing filtering. What is written to the log does not.

The two methods are named after the output they are for: ExceptionHandler::redactForDisplay() for text shown to users or written to the log, and ExceptionHandler::redactForDebugOutput() for output that prints backtraces. replaceSensitiveValues() is the old name of the second one and stays as a deprecated alias until Matomo 7.

When the database server reports that the database account reached one of its limits (MySQL errors 1203 and 1226), a fixed message is shown (General_ExceptionDatabaseResourceLimit). This applies when connecting (the tracker's connection included), on the connection error page, in API and report error responses, and in the log.

A failed email send in a web request now shows a short translated message (General_ExceptionEmailNotSent) and writes the details to the log as a warning. Super users get a variant that says how to see the details (General_ExceptionEmailNotSentSuperUser), because with the default log configuration that warning is not written anywhere. On the command line the full error is shown as before, so core:test-email still gives the reason.

Known limitations

The database account is recognised by the 'user'@'host' form the database server uses in its messages. These cases are accepted as they are:

  • An account name that contains an apostrophe is only partly rewritten.
  • Unrelated text in the same 'a'@'b' form is rewritten too.
  • For the account limit errors the log holds the same fixed message as the response, so it does not say which limit was reached.
  • With the mysqli adapter, the tracker does not recognise an account limit error raised by the charset query right after connecting. It only shows in the tracker's debug output and log.
  • Backtraces in the log (development mode, PIWIK_PRINT_ERROR_BACKTRACE, command line archiving) rely on #[\SensitiveParameter] to hide argument values, which PHP 7.2 to 8.1 ignore. A failed database connection no longer carries the exception of the connect call, so its backtrace holds neither the user name nor the password on any PHP version. The tracker has its own connect call and drops that exception as well. PHPMailer does not mark the password argument of its SMTP authentication.

Apart from the backtrace cases, the text that can still be shown comes from the database server: the account name, and for a failed connection the database host or the database name.

Review

  • [✔] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules

Backport of #25789.

@chippison chippison added this to the 5.14.4 milestone Nov 25, 2026
@chippison chippison added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Nov 25, 2026
@chippison
chippison requested a review from a team November 25, 2026 01:20
@chippison
chippison force-pushed the api-error-message-rewrite-5x branch from 109628a to 9ee6253 Compare November 25, 2026 08:29
@chippison
chippison enabled auto-merge (squash) December 1, 2026 05:43
Comment thread core/Mail/Transport.php Resolved
Build the message for API and report responses in one helper, and keep mail server replies in the log for web requests.
…errors a fixed message

Log records no longer look for the configured credentials, and the limit errors of the database account get a fixed message. Mail failures are logged as a warning.
Brings the backport in line with the latest changes of #25789, with the deprecation noted in the changelog.
@chippison
chippison force-pushed the api-error-message-rewrite-5x branch from 3b6e996 to b5fc68b Compare December 1, 2026 20:41
Adds the tests of #25789 that could not be backported before the SMTP OAuth backend reached 5.x.
@chippison
chippison requested a review from tzi December 1, 2026 21:34
@chippison
chippison merged commit df8563d into 5.x-dev Dec 1, 2026
172 checks passed
@chippison
chippison deleted the api-error-message-rewrite-5x branch December 1, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Development

Successfully merging this pull request may close these issues.

3 participants