Review main Merged

86980[TASK] Provide expression with TypoScript condition errors

Mathias Brodala CR +2 V +2 Easy +12 −2 updated 03/03/25, 12:58

Commit message

TypoScript conditions are commonly tailored to frontend usage and often
miss guards like "traverse()" to avoid accessing undefined objects or
properties. In this case an unspecific RuntimeException was thrown which
mentioned the error but made it hard to understand the reason/context.

We now throw a more specific RuntimeException to mention the TypoScript
condition context and the faulty expression.

The same is done for the error log message in case of TypoScript
condition syntax errors.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Georg Ringer +1
    • Garvin Hicking +1
    • Benni Mack +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Georg Ringer +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 1418

  1. Mathias Brodala uploaded patch set 1 11/13/24, 08:51

  2. Mathias Brodala uploaded patch set 2 11/13/24, 08:59

  3. core-ci voted on patch set 1 V -1 11/13/24, 09:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69393

  4. core-ci voted on patch set 2 V -1 11/13/24, 09:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69394

  5. core-ci voted on patch set 1 V -1 11/13/24, 09:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69393

  6. Stefan Bürk commented on patch set 2 11/13/24, 14:46

    IncludeTreeConditionMatcherVisitor.php:177

    I'd say we should throw a concrete exception in that case and not a generic \RuntimeExcepton again.
  7. Mathias Brodala commented on patch set 2 11/13/24, 14:53

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    While I fully agree I'd say it's beyond the scope of this change. If you have a look at the remaining code in the "TYPO3\CMS\Core\TypoScript" namespace you'll see that only generic exceptions are thrown. All of these should be replaced by specific exceptions IMO.
  8. Garvin Hicking commented on patch set 2 V +1 11/13/24, 18:44

    This is very helpful! Questions about the cause of this show up at least once a week in support channels and would really help a lot.

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    Maybe for new code we could already introduce a new exception (extending runtimeException, so that current consumers still can catch the broader exception), and then we can either have a pre/post patch revisiting the other instances?
  9. Garvin Hicking updated the commit message in patch set 3 V +1 11/13/24, 18:44

  10. core-ci voted on patch set 3 V +1 11/13/24, 18:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69409

  11. Benni Mack commented on patch set 3 CR +1 11/14/24, 07:09

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    maybe we open a new ticket and change these occurrences in v14?
  12. Georg Ringer voted on patch set 3 CR +1 V +1 03/02/25, 15:09

  13. Garvin Hicking commented on patch set 3 CR +1 V +1 03/02/25, 17:08

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    Good for me. Let's get this wrapped as a start.
  14. Christian Kuhn commented on patch set 3 03/03/25, 12:18

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    i think many thrown generic \RuntimeExceptions in TypoScript/ are ok, they often sanitize internal programming stuff. i agree turning this \RuntimeException into something else is out of scope of this patch and changing this will only help us in practice if we actually do something with it on a higher level. my current gut feeling is we still want to let it bubble up into casual exception handler: a broken condition syntax is an (integrator) programming error after all (as opposed to an editor error), and this should stop processing. however, it looks to me as if the catch-and-rethrow of \RuntimeException could and should be relocated to TYPO3\CMS\Core\ExpressionLanguage\Resolver?
  15. Mathias Brodala commented on patch set 3 03/03/25, 12:28

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    > however, it looks to me as if the catch-and-rethrow of \RuntimeException could and should be relocated to TYPO3\CMS\Core\ExpressionLanguage\Resolver? That would however require a more generic exception message which can only refer to "expression". This would make it harder again to understand that the error lies in a faulty TypoScript condition.
  16. Christian Kuhn commented on patch set 3 CR +1 V +1 03/03/25, 12:30

    IncludeTreeConditionMatcherVisitor.php:177 Reply

    Acknowledged. Fine with me then.
  17. Christian Kuhn voted on patch set 3 CR +2 V +2 03/03/25, 12:58

  18. Christian Kuhn merged patch set 4 03/03/25, 12:58