JoomShaper / Helix3

46 stars 37 forks source link

InvalidArgumentException: Error loading menu: api #114

Closed Orgoth closed 1 year ago

Orgoth commented 2 years ago

Bug description

helix3.php calls menu when client is api and throws an exception

https://github.com/JoomShaper/Helix3/blob/e4b01f37d2f2f09ed507b54a0bcf1e91ef68226b/plugins/system/helix3/helix3.php#L60

https://github.com/JoomShaper/Helix3/blob/e4b01f37d2f2f09ed507b54a0bcf1e91ef68226b/plugins/system/helix3/helix3.php#L62

Steps to reproduce

https://docs.joomla.org/J4.x:Joomla_Core_APIs#Get_Single_Article
https://docs.joomla.org/J4.x:Joomla_Core_APIs#Useful_Resources

{ "errors": [ { "code": 500, "title": "Internal server error", "detail": "InvalidArgumentException: Error loading menu: api in /libraries/src/Menu/MenuFactory.php:40\nStack trace:\n#0 /libraries/src/Menu/AbstractMenu.php(124): Joomla\CMS\Menu\MenuFactory->createMenu()\n#1 /libraries/src/Application/CMSApplication.php(518): Joomla\CMS\Menu\AbstractMenu::getInstance()\n#2 /plugins/system/helix3/helix3.php(62): Joomla\CMS\Application\CMSApplication->getMenu()\n#3 /libraries/src/Plugin/CMSPlugin.php(285): plgSystemHelix3->onAfterDispatch()\n#4 /libraries/vendor/joomla/event/src/Dispatcher.php(486): Joomla\CMS\Plugin\CMSPlugin->Joomla\CMS\Plugin\{closure}()\n#5 /libraries/src/Application/EventAware.php(111): Joomla\Event\Dispatcher->dispatch()\n#6 /libraries/src/Application/ApiApplication.php(428): Joomla\CMS\Application\WebApplication->triggerEvent()\n#7 /libraries/src/Application/ApiApplication.php(110): Joomla\CMS\Application\ApiApplication->dispatch()\n#8 /libraries/src/Application/CMSApplication.php(278): Joomla\CMS\Application\ApiApplication->doExecute()\n#9 /api/includes/app.php(54): Joomla\CMS\Application\CMSApplication->execute()\n#10 /api/index.php(31): require_once('...')\n#11 {main}" } ] }

Expected behavior

No error exception should be thrown.

Environment

Solution

add !JFactory::getApplication()->isClient('api') to prevent the error when the api is called, which does not use the template and only returns json.

replace if( !JFactory::getApplication()->isClient('administrator') ) with if( !JFactory::getApplication()->isClient('api') && !JFactory::getApplication()->isClient('administrator') )

RagdollOp commented 2 years ago

I am getting the same error trying to get an article with the api and postman. I am using Helix Ultimate 2.0.11 and can not find anything else besides your post here about the (Error loading menu: api) when using Joomla 4 api. Do you think this is the same issue? Thanks!

Orgoth commented 2 years ago

@RagdollOp
That's very possible, I just stumbled across your post on Joomshaper as well. Important, if the support tells you that they will make an update very soon, that usually means that it will take months.

Getting back to your problem. Would you please enable the debug mode? Then trigger the problem again and please copy the stacktrace of the message. Then I should be able to tell where exactly the problem is and how you can temporarily fix it until Joomshaper makes an update.

RagdollOp commented 2 years ago

So I narrowed it down to an issue with EasyBlog. Once I disabled the EasyBlogUsers plugin I no longer got the "Error loading menu: api". I do get another error though but it is no longer related to EasyBlog. I plan to contact their support to let them know of the issue.

`error Uncaught Throwable of type InvalidArgumentException thrown with message "Error loading menu: api". Stack trace: #0 [ROOT]/libraries/src/Application/CMSApplication.php(519): Joomla\CMS\Menu\MenuFactory->createMenu()

1 [ROOT]/administrator/components/com_easyblog/includes/easyblog.php(548): Joomla\CMS\Application\CMSApplication->getMenu()

2 [ROOT]/plugins/user/easyblogusers/easyblogusers.php(31): EB::config()

3 [ROOT]/libraries/src/Extension/ExtensionManagerTrait.php(234): plgUserEasyBlogUsers->__construct()

4 [ROOT]/libraries/src/Extension/ExtensionManagerTrait.php(157): Joomla\CMS\Application\CMSApplication->loadPluginFromFilesystem()

5 [ROOT]/libraries/src/Extension/ExtensionManagerTrait.php(96): Joomla\CMS\Application\CMSApplication->loadExtension()

6 [ROOT]/libraries/src/Plugin/PluginHelper.php(221): Joomla\CMS\Application\CMSApplication->bootPlugin()

7 [ROOT]/libraries/src/Plugin/PluginHelper.php(181): Joomla\CMS\Plugin\PluginHelper::import()

8 [ROOT]/libraries/src/Application/CMSApplication.php(819): Joomla\CMS\Plugin\PluginHelper::importPlugin()

9 [ROOT]/libraries/src/Application/ApiApplication.php(297): Joomla\CMS\Application\CMSApplication->login()

10 [ROOT]/libraries/src/Application/ApiApplication.php(107): Joomla\CMS\Application\ApiApplication->route()

11 [ROOT]/libraries/src/Application/CMSApplication.php(294): Joomla\CMS\Application\ApiApplication->doExecute()

12 [ROOT]/api/includes/app.php(53): Joomla\CMS\Application\CMSApplication->execute()

13 [ROOT]/api/index.php(31): require_once('...')`

Orgoth commented 2 years ago

From this Stack trace you provided, I can see, the problem is still related to easyblog.

#2 [ROOT]/plugins/user/easyblogusers/easyblogusers.php(31): EB::config()

If I remember right, this error happens, if an extension delivers wrong parameters to Joomla.
I do not own EasyBlog so I can only give a direction.
Within the "easyblogusers.php(31): EB::config()" there should be a similar query, like the one from joomshaper/helix3.

Can you possibly provide an excerpt from this section?
From line 31, 5 lines up and down.

mi-prakash commented 1 year ago

@Orgoth This issue will be fixed in the next update which will be released within a few days. Thanks for your patience.

Orgoth commented 1 year ago

Was fixed in this commit: https://github.com/JoomShaper/Helix3/commit/ace83c8a7544c4375c420162d5eca19456242017#diff-feacae3a7885b27d5c5208a904da48c90c900f69e31185bf655b6e586fe7436bR63

landed1 commented 9 months ago

Hi I found this as I am starting to use the API experimentally. I am using a rockettheme which uses gantry under the hood. So any help in getting a handle on a fix would be good thank you.