Typo3ExtensionUtils icon indicating copy to clipboard operation
Typo3ExtensionUtils copied to clipboard

Extract does not offer correct return value on Exception

Open cognifloyd opened this issue 9 years ago • 5 comments

Using "t3xutils.phar extract", the exit code is always 0, even if there was an exception.

The exit code is determined by $success when Dispatcher exits here: https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Dispatcher.php#L91

$status is supposed to be set in extractCommand with the return value of extractAction: https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Dispatcher.php#L216

But, extractAction does not have a return value: https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Controller/T3xController.php#L73

Also, the exception catcher does not exit with any error codes: https://github.com/etobi/Typo3ExtensionUtils/blob/master/bin/t3xutils.php#L14

Either the extractAction needs to somehow return an appropriate boolean, or the exception catcher needs to exit with an error code.

cognifloyd avatar May 28 '15 23:05 cognifloyd

As you already digged into this: could you provide a patch/PR?

etobi avatar May 29 '15 07:05 etobi

Which solution would you prefer? Does the exit line here ever return any error codes (should the fix focus on this)? https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Dispatcher.php#L91

Or should I focus on catching exceptions here: https://github.com/etobi/Typo3ExtensionUtils/blob/master/bin/t3xutils.php#L14

cognifloyd avatar May 30 '15 09:05 cognifloyd

i guess catching the exception and returning the correct exit code there might be the "right" way. All actions throw exceptions, if they don't succeed.

However, to not confuse the next developer looking at https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Dispatcher.php#L91 this should be cleaned up, too.

etobi avatar Jun 03 '15 12:06 etobi

I just double checked the actions. Seems like some actions do return TRUE/FALSE (like https://github.com/etobi/Typo3ExtensionUtils/blob/master/lib/etobi/extensionUtils/Controller/TerController.php#L125).

I like to suggest to streamline the error handling (always throw an exception, instead of returning TRUE/FALSE) in all actions, implementing an "own Exception" (e.g. ActionFailedException extends \Exception) and catch that in the Dispatcher or t3xutils.php

What do you think?

etobi avatar Jun 03 '15 13:06 etobi

That could work. It'll be awhile before I can dig into this again.

cognifloyd avatar Jul 17 '15 02:07 cognifloyd