Review main Merged

85138[FEATURE] Allow argument mapping exception-handling in ActionController

Torben Hansen CR +2 V +2 Normal +184 −27 updated 09/13/24, 09:39

Commit message

Extbase controller argument mapping can result in several exceptions
being thrown. Extension authors however have no public API method
for handling those exceptions, resulting in possibly overwriting
internal methods of `ActionController`.

This change introduces the method `handleArgumentMappingExceptions`
in `ActionController` and the configuration options:

* `mvc.showPageNotFoundIfTargetNotFoundException`
* `mvc.showPageNotFoundIfRequiredArgumentIsMissingException`

Extension authors can now either configure handling of commonly
thrown exceptions during argument mapping, or implement a custom
exception response handling.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Markus Klein +1
    • Mathias Brodala +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Markus Klein +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 1

Files 5

Review log 5668

Show 3343 earlier messages
  1. Torben Hansen uploaded patch set 1 07/06/24, 11:56

  2. core-ci voted on patch set 1 V -1 07/06/24, 12:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61095

  3. Torben Hansen uploaded patch set 2 V -1 07/07/24, 13:10

  4. core-ci voted on patch set 2 V +1 07/07/24, 13:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61138

  5. Torben Hansen uploaded patch set 3 V +1 07/07/24, 17:46

  6. core-ci voted on patch set 3 V +1 07/07/24, 17:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61141

  7. Mogens Fiebrandt commented on patch set 3 07/08/24, 02:30

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:22

    Got a typo here
  8. Torben Hansen uploaded patch set 4 V +1 07/08/24, 06:21

  9. Torben Hansen commented on patch set 3 07/08/24, 06:21

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:22 Reply

    Done
  10. core-ci voted on patch set 4 V +1 07/08/24, 06:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61160

  11. Mogens Fiebrandt voted on patch set 4 CR +1 07/08/24, 08:57

  12. Christian Kuhn commented on patch set 4 07/08/24, 14:45

    ActionController.php:769

    still a bit unsure on the general patch, but what pops up immediately: why is this public?
  13. Torben Hansen uploaded patch set 5 CR +1 V +1 07/08/24, 16:16

  14. Torben Hansen commented on patch set 5 07/08/24, 16:19

    ActionController.php:769 Reply

    Uops, the method should be `protected`, as only classed extending `ActionController` should be able to use/overwrite the method. Updated the patch.
  15. core-ci voted on patch set 5 V +1 07/08/24, 16:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61181

  16. Daniel Goerz commented on patch set 5 07/16/24, 22:47

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:25

    exceptions
  17. Georg Ringer commented on patch set 6 V +1 07/17/24, 05:16

    Published edit on patch set 5.
  18. Georg Ringer commented on patch set 6 CR +1 V +1 07/17/24, 05:17

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:25 Reply

    Done
  19. core-ci voted on patch set 6 V +1 07/17/24, 05:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61674

  20. Mogens Fiebrandt voted on patch set 6 CR +1 07/17/24, 07:58

  21. Daniel Goerz commented on patch set 6 07/17/24, 08:12

    Hi Torben, I welcome the idea of this patch, as this is something I frequently have to deal with. What do you think about handling the exception in the processRequest() method via try-catch block, so that existing overrides of mapRequestArgumentsToControllerArguments() do not silently switch to the new handling without noticing?
  22. Torben Hansen commented on patch set 6 07/18/24, 05:54

    Reply

    I had it in `processRequest()` first, but decided to leave the try/catch block out of that function, since I think `processRequest()` should be as simple/readable as possible. Users overriding the internal function `mapRequestArgumentsToControllerArguments` will however not silently switch to the new handling (except they call `parent::mapRequestArgumentsToControllerArguments`) and currently, only exceptions are catched, it the new configuration options are set. Main intention of this patch is to give extension authors a public API which allows custom exception handling in case of argument mapping errors and without the need to override internal functions.
  23. Daniel Goerz commented on patch set 6 07/22/24, 15:20

    Reply

    My thinking was: If you currently handle this yourself, you probably have an override of `mapRequestArgumentsToControllerArguments()` in place to catch exceptions thrown there (the override of course is calling parent). If you switch to the new default behaviour of always responding with 404 (by setting the new option, so it not silent, I aggree), you have to change your override to an override of `handleArgumentMappingExceptions()` whenever you want to change the default behaviour on a per controller base. However this is by no means crucial. The extra effort is very manageable and custom overrides are phrone to breaking in major updates anyway. So, fine with me to keep it as is.
  24. Daniel Goerz voted on patch set 6 CR +1 07/22/24, 15:21

  25. Garvin Hicking uploaded patch set 7 CR +1 V +1 09/04/24, 15:55

    Rebase and minor wording changes
  26. Garvin Hicking commented on patch set 7 09/04/24, 15:56

    Rebased set and minor spelling adjustments.

    ActionController.php:785

    In this case we have the same exception code for two possible exceptions. I wonder if it would be beneficial to have distinct codes instead?
  27. Garvin Hicking voted on patch set 7 CR +1 09/04/24, 15:57

  28. core-ci voted on patch set 7 V +1 09/04/24, 16:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64783

  29. Chris Müller commented on patch set 7 09/04/24, 16:37

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:25

    I assume, this is TypoScript configuration? To make it for integrators easier reading this changelog, maybe we should hint that ("... can be enabled by TypoScript"). What do you think?

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:34

    Suggestion: When setting one of these options to 1 ...
  30. Garvin Hicking commented on patch set 7 09/05/24, 09:11

    See https://forge.typo3.org/issues/104828 for a related thing to address (request should set a http/5xx error when thrown and not caught?
  31. Garvin Hicking commented on patch set 8 CR +1 V +1 09/05/24, 16:08

    Published edit on patch set 7.
  32. Garvin Hicking commented on patch set 8 CR +1 09/05/24, 16:09

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:25 Reply

    Done

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:34 Reply

    Done
  33. core-ci voted on patch set 8 V +1 09/05/24, 16:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64871

  34. Georg Ringer voted on patch set 8 CR +1 09/06/24, 08:39

  35. Torben Hansen commented on patch set 8 09/10/24, 07:13

    Reply

    The references issue #104828 is not extbase related and should therefore not be addressed within this patch.

    ActionController.php:785 Reply

    The exceptions are catched on intention and triggers the configured page not found error handler. AFAIK there is no possibility to "do something" with the exception code at this level, since just the general TYPO3 404 response is generated. So I think it is ok to have one exception code here.
  36. Garvin Hicking commented on patch set 8 V +1 09/10/24, 08:26

    Reply

    OK; I seem to have misread that - I thought the current exception would still yield a HTTP
    (verified working; please see comment on "naming things" and the docs)

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:27

    I think this should be `plugin.tx_yourextension.mvc...` here? If you copy+paste this one to a TypoScript configuration it won't apply.

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28

    Regarding "naming things". We already have a setting called "throwPageNotFoundExceptionIfActionCantBeResolved". So I think we should also prefix this with "throw" here, which also makes the intent clearer why one needs to set it to "1" to take effect (and 0 to disable it and receive the actual exception)...?
  37. Torben Hansen uploaded patch set 9 CR +1 V +1 09/10/24, 08:38

  38. Torben Hansen commented on patch set 8 09/10/24, 08:43

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:27 Reply

    Good spot. I separated this, so we now show the global configuration option and on extension basis.

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28 Reply

    I do not agree here. Although we from a technical perspective throw an exception, the result will not be, that TYPO3 shows an exception. Instead, the general 404 error (either from TYPO3 or the PageErrorHandler if configured) will be shown, so I think the current naming fits better. We could prefix it with "show" (showPageNotFoundIfActionCantBeResolved), which would make it more clear. What do you think?
  39. core-ci voted on patch set 9 V +1 09/10/24, 08:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65193

  40. Garvin Hicking commented on patch set 9 09/10/24, 10:57

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28 Reply

    Yes, "show" would work well for me to get my mind wrapped about what "0" or "1" actually means :-)
  41. Torben Hansen uploaded patch set 10 V +1 09/10/24, 12:23

  42. Torben Hansen commented on patch set 10 09/10/24, 12:23

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28 Reply

    Done
  43. core-ci voted on patch set 10 V +1 09/10/24, 12:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65236

  1. Garvin Hicking commented on patch set 10 CR +1 V +1 09/10/24, 12:55

    👍
  2. Markus Klein commented on patch set 10 09/10/24, 13:06

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28

    isn't this `config.tx_extbase`? \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager::getExtbaseConfiguration
  3. Markus Klein commented on patch set 10 09/10/24, 13:07

    ActionController.php:817

    What happens if this is triggered within a BE module?
  4. Torben Hansen commented on patch set 10 09/10/24, 13:19

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:28 Reply

    Good spot.

    ActionController.php:817 Reply

    In this case, also a 404 (page not found) is shown instead of the exception. Most likely not the best to show a 404 here, but extension authors could now override `handleArgumentMappingExceptions` to handle those scenarios in BE modules.
  5. Garvin Hicking commented on patch set 11 CR +1 V +1 09/10/24, 14:06

    Published edit on patch set 10.
  6. Garvin Hicking voted on patch set 11 CR +1 V +1 09/10/24, 14:07

  7. core-ci voted on patch set 11 V +1 09/10/24, 14:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65257

  8. Markus Klein voted on patch set 11 CR +1 09/10/24, 18:26

  9. Stefan Froemken commented on patch set 11 09/10/24, 21:07

    Nice one

    ControllerArgumentsMappingTest.php:136

    Duplicate "Exception"?
  10. Garvin Hicking commented on patch set 11 09/10/24, 21:12

    ControllerArgumentsMappingTest.php:136 Reply

    The name is "TargetNotFoundException", which is an Exception ("TargetNotFoundException"-Exception), so technically this is alright, albeit funny. :)
  11. Garvin Hicking commented on patch set 11 09/10/24, 21:12

    Reply

    Acknowledged
  12. Stefan Froemken voted on patch set 11 CR +1 09/10/24, 21:29

  13. Simon Schaufelberger voted on patch set 11 CR +1 V +1 09/11/24, 09:48

  14. Thomas Hohn voted on patch set 11 CR +1 09/11/24, 09:56

  15. Mathias Brodala commented on patch set 11 09/13/24, 07:43

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:34

    Should we mention that this can also be configured per-plugin as "3rd level"? E.g. > plugin.tx_yourextension_firstplugin.mvc.showPageNotFoundIfTargetNotFoundException = 1
  16. Sebastian Iffland voted on patch set 11 CR +1 09/13/24, 07:56

  17. Garvin Hicking commented on patch set 11 09/13/24, 08:32

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:34 Reply

    Yes, I'd say so. I can adress it once I get over losing all votes because of it 🥲
  18. Garvin Hicking commented on patch set 12 CR +1 V +1 09/13/24, 08:35

    Published edit on patch set 11.
  19. Garvin Hicking commented on patch set 12 CR +1 V +1 09/13/24, 08:35

    Feature-104321-AllowHandlingOfArgumentMappingExceptionsInActionController.rst:34 Reply

    Done
  20. Mathias Brodala voted on patch set 12 CR +1 09/13/24, 08:37

  21. core-ci voted on patch set 12 V +1 09/13/24, 08:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65638

  22. Markus Klein voted on patch set 12 CR +1 V +1 09/13/24, 08:47

  23. Simon Schaufelberger voted on patch set 12 CR +1 V +1 09/13/24, 08:54

  24. Garvin Hicking voted on patch set 12 CR +2 V +2 09/13/24, 09:25

  25. Garvin Hicking merged patch set 13 09/13/24, 09:39