Review main Merged

84004[BUGFIX] Mitigate exceptions in `LogDataTrait::formatLogDetailsStatic`

Thomas Hohn CR +2 V +2 Hard +301 −49 updated 09/06/24, 19:14

Commit message

`LogDataTrait::formatLogDetailsStatic()` simple used `vsprintf()`
in case that the string contains any `%` characters and throws
either a `\ValueError` or `\ArgumentCountError` depending if no
value exists or the count does not match.

It is not reliable and implement additional lexing here to avoid
the exception by not calling `vsprintf()` upfront.

This change calls `vsprintf()` and handles the mentioned exceptions
and use the fallback handling in case exception has been thrown as
a simplefied approach. Tests are added to cover legacy, mixed and
new log format option along with static and instanced method calls.

Note that a minor inline PHP DocBlock annotation has been added
in `LogDataTrait` to mitigate detection issues of PHPStan, which
allows now to remove baseline ignore patterns in the same run.

Used command(s):

> Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Garvin Hicking +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 2333

Show 68 earlier messages
  1. Thomas Hohn uploaded patch set 1 04/23/24, 11:19

  2. Thomas Hohn updated the commit message in patch set 2 04/23/24, 11:20

  3. core-ci voted on patch set 1 V +1 04/23/24, 11:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56568

  4. core-ci voted on patch set 2 V +1 04/23/24, 11:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56569

  5. Christian Kuhn commented on patch set 2 CR -1 04/23/24, 13:05

    LogDataTrait.php:59

    This feels odd: if there is a '%' in text that is not meant as formatting, it will fail, too, right? it feels as if the proposed solution does not really improve the situation here. Couldn't we just catch \ValueError here and then fallback somehow?
  6. Thomas Hohn commented on patch set 2 04/23/24, 13:47

    LogDataTrait.php:59 Reply

    This comment is kind of weird too // Handle legacy "%s" placeholders Since it actually handles % anything and then in the end all %s are replaced by '' But what should the fallback be - do nothing? And then just replace %s with '' ?
  7. Thomas Hohn uploaded patch set 3 CR -1 V +1 04/23/24, 14:00

  8. Thomas Hohn commented on patch set 3 04/23/24, 14:04

    LogDataTrait.php:59 Reply

    Proposed a different attempt
  1. core-ci voted on patch set 3 V +1 04/23/24, 14:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56581

  2. Stefan Bürk commented on patch set 3 04/23/24, 15:09

    LogDataTrait.php:59 Reply

    What lolli/we meant was: 1. try-catch do the vsprintf() without the str_contains() check at all. 2. in case of a value expection use the fallback. getting a suitable check is not really manageable. Or use only the "$substitute" emtpy check. The point was, that the str_contains() call is not good at all in any case and missleading. Would it be okay for you to provide such a attempt/change ?
  3. Thomas Hohn uploaded patch set 4 V +1 04/23/24, 17:08

  4. core-ci voted on patch set 4 V -1 04/23/24, 17:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56597

  5. Thomas Hohn uploaded patch set 5 V -1 04/23/24, 17:14

  6. core-ci voted on patch set 5 V +1 04/23/24, 17:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56598

  7. Garvin Hicking commented on patch set 5 09/05/24, 08:43

    This looks good to me now, however maybe we could rewrite the test to use a dataprovider instead to increase legibility and better test failure reporting? (I can offer to do that too, but only after feature freeze)
  8. Stefan Bürk commented on patch set 5 09/05/24, 20:41

    Reply

    Yes, either sigle test methods or DataProvider - but different calls/expectation for different input in one test case is not good. Will change that ....

    LogDataTraitTest.php:26

    Test case class should not implement that trait directly. To keep test cases clean a class implementing the trait needs to be constructed. Due to the simple nature of the trait, this can be done simply with: ```php $subject = new class() { use LogDataTrait; public static callFormatLogDetailsStatic( string $detailString, array $substitutes ): string { return self::formatLogDetailsStatic($detailString, array $substitures); } } ``` or with a test fixture class allong with a dispatcher method towards the protected method.
  9. Stefan Bürk commented on patch set 5 CR -1 09/05/24, 20:45

    on it

    LogDataTraitTest.php:32

    `assertEquals()` does not take type into account and thus we use assertSame() over `assertEquals()` to mitigate eventually relaxed issues.
  10. Stefan Bürk uploaded patch set 6 CR -1 V +1 09/06/24, 14:09

  11. Stefan Bürk uploaded patch set 7 09/06/24, 14:12

  12. Stefan Bürk updated the commit message in patch set 8 09/06/24, 14:13

  13. Stefan Bürk commented on patch set 8 09/06/24, 14:14

    Reply

    Done

    Reply

    Done

    LogDataTraitTest.php:26 Reply

    Done

    LogDataTraitTest.php:32 Reply

    Done
  14. core-ci voted on patch set 6 V -1 09/06/24, 14:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64966

  15. Stefan Bürk uploaded patch set 9 09/06/24, 14:17

  16. Stefan Bürk uploaded patch set 10 09/06/24, 14:19

  17. core-ci voted on patch set 8 V -1 09/06/24, 14:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64968

  18. core-ci voted on patch set 7 V -1 09/06/24, 14:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64967

  19. Stefan Bürk updated the commit message in patch set 11 09/06/24, 14:21

  20. core-ci voted on patch set 10 V -1 09/06/24, 14:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64970

  21. core-ci voted on patch set 11 V +1 09/06/24, 14:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64971

  22. Stefan Bürk voted on patch set 11 CR +1 V +1 09/06/24, 14:39

  23. Garvin Hicking voted on patch set 11 CR +1 V +1 09/06/24, 18:45

  24. Stefan Bürk voted on patch set 11 CR +2 V +2 09/06/24, 18:57

  25. Stefan Bürk merged patch set 12 09/06/24, 19:14