When the menu rebuild fails, a fatal error occurs since the model doesn't support a getMessage method. Also the language string it tries to use, doesn't exist.
Solution
Use getError instead of getMessage and add the language string.
Testing
To reproduce the issue you need to get the rebuild to fail. For that you can go to the #__menu table and delete the first row (id 1, root). That will break the nested set for sure.
See that you get a fatal error.
After applying the PR, you will get an error show that the rebuild failed with a lengthy exception message,
We can change the message to something more general and remove the sprintf / getError stuff completely.
I just don't know if there are more than one way to break the rebuild.
Error
Rebuild failed: exception 'UnexpectedValueException' with message 'MenusTableMenu::getRootId' in
C:\xampp\htdocs\J3x\J34\j341\libraries\joomla\table\nested.php:1270
Stack trace:
#0 C:\xampp\htdocs\J3x\J34\j341\libraries\joomla\table\nested.php(1297): JTableNested->getRootId()
#1 C:\xampp\htdocs\J3x\J34\j341\administrator\components\com_menus\models\item.php(1108): JTableNested->rebuild()
#2 C:\xampp\htdocs\J3x\J34\j341\administrator\components\com_menus\controllers\menus.php(108): MenusModelItem->rebuild()
#3 C:\xampp\htdocs\J3x\J34\j341\libraries\legacy\controller\legacy.php(728): MenusControllerMenus->rebuild()
#4 C:\xampp\htdocs\J3x\J34\j341\administrator\components\com_menus\menus.php(18): JControllerLegacy->execute('rebuild')
#5 C:\xampp\htdocs\J3x\J34\j341\libraries\cms\component\helper.php(391): require_once('C:\xampp\htdocs...')
#6 C:\xampp\htdocs\J3x\J34\j341\libraries\cms\component\helper.php(371): JComponentHelper::executeComponent('C:\xampp\htdocs...')
#7 C:\xampp\htdocs\J3x\J34\j341\libraries\cms\application\administrator.php(98): JComponentHelper::renderComponent('com_menus')
#8 C:\xampp\htdocs\J3x\J34\j341\libraries\cms\application\administrator.php(152): JApplicationAdministrator->dispatch()
#9 C:\xampp\htdocs\J3x\J34\j341\libraries\cms\application\cms.php(252): JApplicationAdministrator->doExecute()
#10 C:\xampp\htdocs\J3x\J34\j341\administrator\index.php(42): JApplicationCms->execute()
#11 {main}
Expected:
Error
Rebuild failed due to database error.
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6783.