Bug #81813

ShorcutButton doesn't handle exceptions in __toString

Added by Tizian Schmidlin over 2 years ago. Updated over 2 years ago.

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

0%

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

History

#1 Updated by Tizian Schmidlin over 2 years ago

  • Description updated (diff)

Also available in: Atom PDF