Project

General

Profile

Actions

Bug #81813

closed

ShorcutButton doesn't handle exceptions in __toString

Added by Tizian Schmidlin over 7 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Start date:
2017-07-06
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

In TYPO3\CMS\Backend\Template\Components\Buttons\Actions\ShortcutButton the __toString()-Method might throw an exception, since the render-Method uses the ModuleTemplate->makeShortcutIcon-Method which itself may throw an exception, since this calls BackendUtility::shortcutExists-Method which itself checks the database with a prepared statement. This might happen if the table lock cannot be acquired for some reason.

Now I don't think that every method making database calls should anootate @throws if it doesn't handle database exception since this might be handled somewhere higher already but PHPs magic __toString-method cannot throw an exception and I think that there the exception should be caught and either silenced or handled accordingly to the current environment.

My simple approach would be as follows:

    /**
     * Renders the button
     *
     * @return string
     */
    public function __toString()
    {
        try {
            return $this->render();
        } catch(\Exception) {
            // ensure that the exception is handled properly (regarding logging and info text if needed for the shortcut button)
            return '';
        }
    }

I'll leave the category open on purpose since I'm not sure to which "Backend"-category this belongs.

Regards
Tizian

Actions

Also available in: Atom PDF