Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined index errorCount at LoggerDataCollector #36159

Closed
dbalabka opened this issue Mar 21, 2020 · 3 comments
Closed

Undefined index errorCount at LoggerDataCollector #36159

dbalabka opened this issue Mar 21, 2020 · 3 comments

Comments

@dbalabka
Copy link

dbalabka commented Mar 21, 2020

Symfony version(s) affected: >=3.4.37

Description
The following error might appear which blocks Debug Toolbar to be loaded:

Uncaught PHP Exception ErrorException: "Notice: Undefined index: errorCount" at /Users/torinaki/www/htdocs/fithealthy2/vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php line 190

How to reproduce
TBD

@trigger_error("1", E_USER_DEPRECATED)

Such a log message might be thrown by:
https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Config/Definition/ArrayNode.php#L238
in case if configuration child is deprecated and depreciation message for some reason is "1"

Possible Solution
Fix logic of:

private function sanitizeLogs(array $logs)

  1. There no guarantee that "errorCount" exists but it is not a root cause.
    $sanitizedLogs[$message]['errorCount'] += $exception->count;
  2. $sanitizedLogs contains numeric and assoc. keys. It should be avoided:

    $sanitizedLogs[$message]['errorCount'] += $exception->count;

Additional Context
It happened because of incorrect passed deprecation message:
https://github.com/Sylius/SyliusMailerBundle/blob/1.4/src/Bundle/DependencyInjection/Configuration.php#L76
It was possible because of missing type hint:
https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Config/Definition/BaseNode.php#L170
which is fixed in 5.0 version of Symfony:
https://github.com/symfony/symfony/blob/5.0/src/Symfony/Component/Config/Definition/BaseNode.php#L204

@fancyweb
Copy link
Contributor

Status: reviewed

I'm looking at this issue. I think the easiest way to deal with this is simply to prepend a fixed string to the messages so numeric and message keys never collide.

@chancegarcia
Copy link

I ran into this issue when a Configuration TreeBuilder node used setDeprecated(true) instead of a string

nicolas-grekas added a commit that referenced this issue Mar 31, 2020
…in the sanitized logs processing (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel][LoggerDataCollector] Prevent keys collisions in the sanitized logs processing

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #36159
| License       | MIT
| Doc PR        | -

`$sanitizedLogs` is used with numeric and "associative" keys. To prevent collisions when the message is a number, we can simply prepend all messages with a random letter (so we avoid a behavior refactor). It doesn't matter since they key is only used for the processing, it is dropped at the end.

Commits
-------

79fe888 [HttpKernel][LoggerDataCollector] Prevent keys collisions in the sanitized logs processing
symfony-splitter pushed a commit to symfony/http-kernel that referenced this issue Mar 31, 2020
…in the sanitized logs processing (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel][LoggerDataCollector] Prevent keys collisions in the sanitized logs processing

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | symfony/symfony#36159
| License       | MIT
| Doc PR        | -

`$sanitizedLogs` is used with numeric and "associative" keys. To prevent collisions when the message is a number, we can simply prepend all messages with a random letter (so we avoid a behavior refactor). It doesn't matter since they key is only used for the processing, it is dropped at the end.

Commits
-------

79fe888072 [HttpKernel][LoggerDataCollector] Prevent keys collisions in the sanitized logs processing
@dbalabka
Copy link
Author

dbalabka commented Apr 2, 2020

@fancyweb thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants