genecommerce / module-encryption-key-manager

Tooling to help generate and invalidate magento encryption keys
GNU Lesser General Public License v3.0
54 stars 14 forks source link

Fix "Area code is already set" error #29

Closed dannynimmo closed 1 month ago

dannynimmo commented 1 month ago

I am getting "Area code is already set" on my installation. This fix catches the exception and allows the process to continue on.

convenient commented 1 month ago

Hello @dannynimmo

Thank you for the PR. This would imply that the constructor of one of your other console commands is calling "setAreaCode" which is conflicting with this bit of code.

I'm happy to merge this, however before I do that I need to verify that this code is still functioning properly

https://github.com/pepe1518/magento2/blob/89adbabc2a295c9b6f88768d541fd2858f59aae5/vendor/magento/module-encryption-key/Model/ResourceModel/Key/Change.php#L144

Seeing as I cannot replicate the issue with your Instance could you please put a breakpoint at the above line, and verify that the $paths variable is not empty? It needs to have correctly initialised as adminhtml to be functional which should be sufficient with the app emulation call, but good to check.

Thanks

dannynimmo commented 1 month ago

Hey @convenient that's good insight, thanks for that. I will dig into our commands to track that down.

FWIW I've checked and confirmed $paths is all good: Screenshot 2024-07-23 at 7 44 18 PM

convenient commented 1 month ago

Thanks for testing @dannynimmo that looks sensible to me.

You may also be interested in this module https://github.com/run-as-root/magento-cli-auto-proxy, I have not tested it, but it aims to make all the console commands inject their dependencies as proxy. Which may help in your situation but i'm not sure.