Review main Merged Breaking

87718[!!!][TASK] Throw specific exception in Folder->getSubFolder()

Christian Kuhn CR +2 V +2 Normal +101 −5 updated 01/13/25, 15:42

Commit message

Throwing "global" exception at runtime that are expected to be
caught by calling code is almost always a code smell as outlined
in [1] for a long time already.

We still have various places in the core that violate this,
especially FAL/Resource handling is problematic in this area.

The patch rules out one of such cases:

Folder->getSubFolder() throws a \InvalidArgumentException if the
folder does not exist. There is no hasSubFolder() or similar.
Code thus tends to use an "optimistic" approach: "Get the sub folder,
and if this throws, create it". This forces \InvalidArgumentException
to be caught. This may hide away lower level errors which are
not intended to be caught, which may in turn lead to other issues.

The patch changes getSubFolder() to throw the specific
FolderDoesNotExistException instead, allowing consumers to
handle the "optimistic" approach correctly and without side
effects. Since FolderDoesNotExistException does not inherit from
\InvalidArgumentException, the change has to be considered
breaking. There is no good way around this, so we document this
in a ReST file and outline proper handling within extensions.

[1] https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/CodingGuidelines/PhpArchitecture/WorkingWithExceptions.html

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Mathias Brodala +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • Mathias Brodala +1
    • core-ci +1 CI

Issues 2

Files 4

Review log 1114

  1. Christian Kuhn uploaded patch set 1 01/13/25, 13:52

  2. Mathias Brodala commented on patch set 1 01/13/25, 13:55

    Folder.php:257

    Technically this is a breaking change since the "new" exception does not inherit from InvalidArgumentException, thus an existing try/catch will not catch it anymore. But aside from that I'll always support switching to specific errors.
  3. core-ci voted on patch set 1 V +1 01/13/25, 13:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72353

  4. Christian Kuhn commented on patch set 1 01/13/25, 14:04

    Folder.php:257 Reply

    that's true. that's why this is a WIP and i think it should go to v14 only, i wanted to see if CI finds something else, first. i'll now add a .rst and explain the impact.
  5. Christian Kuhn uploaded patch set 2 V +1 01/13/25, 14:26

  6. core-ci voted on patch set 2 V +1 01/13/25, 14:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72355

  7. Christian Kuhn updated the commit message in patch set 3 V +1 01/13/25, 14:39

  8. Christian Kuhn commented on patch set 2 01/13/25, 14:39

    Folder.php:257 Reply

    Done
  9. Mathias Brodala voted on patch set 3 CR +1 01/13/25, 14:44

  10. core-ci voted on patch set 3 V +1 01/13/25, 14:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72356

  11. Mathias Brodala voted on patch set 3 V +1 01/13/25, 15:00

  12. Stefan Bürk voted on patch set 3 CR +1 V +1 01/13/25, 15:02

  13. Christian Kuhn voted on patch set 3 CR +2 V +2 01/13/25, 15:42

  14. Christian Kuhn merged patch set 4 01/13/25, 15:42