Project

General

Profile

Actions

Bug #81813

closed

ShorcutButton doesn't handle exceptions in __toString

Added by Tizian Schmidlin almost 7 years ago. Updated about 2 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 #1

Updated by Tizian Schmidlin almost 7 years ago

  • Description updated (diff)
Actions #2

Updated by Susanne Moog about 4 years ago

  • Status changed from New to Needs Feedback

"... but PHPs magic __toString-method cannot throw an exception ..."
Yes it can, and it's actually not a problem, but behaves the same way as all other exceptions in the backend. What did you mean by that sentence?

Actions #3

Updated by Christian Kuhn about 2 years ago

  • Status changed from Needs Feedback to Closed

Hey. This is most likely solved at least with v11: The shortcut API got a major overhaul in v11 and most of the mentioned methods don't exist anymore as such. I hope it's ok to close here for now. Let's start with a fresh issue if there are still problems in recent core versions.

Actions

Also available in: Atom PDF