106 votes
Accepted

'Area code not set' issue in custom CLI commands in Magento 2

The area is not set in Magento CLI (it is not required for any core commands). It can be set at the beginning of your command's execute method: /** @var \Magento\Framework\App\State **/ private $...
Alex Paliarush's user avatar
47 votes

'Area code not set' issue in custom CLI commands in Magento 2

I've stumbled into this problem again today and it's important to know that this problem is thrown whenever a dependency down the chain initiates an instance that needs to know the state of the ...
Giel Berkers's user avatar
  • 12.2k
35 votes
Accepted

Exception handling in Magento 2

The easiest way to start logging your exceptions would be to inject the Psr\Log\LoggerInterface into your class's constructor: private $logger; public function __construct(\Psr\Log\LoggerInterface $...
brendanWeb's user avatar
23 votes

'Area code not set' issue in custom CLI commands in Magento 2

You shouldn't use setAreaCode in the __construct for CLI commands. When you run any command Magento collect and create instance for each script registered in your application. If there are more than ...
Eugene Kovalyov's user avatar
22 votes

Magento 2: Requested store is not found

I just recently came across this same situation after migrating from Magento 1.6.1.0 to 2.1.4 and hope my answer can be of assistance. The problem came from deleting multiple stores 96 of them to be ...
Yamaha32088's user avatar
20 votes
Accepted

Magento 2: Requested store is not found

You need to run the following query in your database, and then try to open the website. SET FOREIGN_KEY_CHECKS=0; UPDATE `store` SET store_id = 0 WHERE code='admin'; UPDATE `store_group` SET group_id ...
Dhiren Vasoya's user avatar
14 votes
Accepted

Magento2 - ProductRepository how to catch Exception if sku does not exist

I thought I could catch that using generic php Exception class, but it seems we need to use the concrete throwed Exception Using this code, then the try/catch block works try { $product = $...
Raul Sanchez's user avatar
  • 3,174
12 votes

'Area code not set' issue in custom CLI commands in Magento 2

In most cases exception is caused by some actions performed in console command. Solution (instead of setting area code) is to emulate area code and perform action using $this->state->...
Bartosz Kubicki's user avatar
12 votes

Magento2.2 - - Failed to read session data

Adding an answer for posterity as this was already correctly resolved in the comments by Anthony. When using Redis to store the session data, the Warning: session_start(): Failed to read session data ...
Marina Gociu's user avatar
  • 1,261
11 votes

Magento 2.0: Exception printing is disabled by default for security reasons

Exception errors are stored as number named files in var/report/ except if the directory permissions are so messed up that Magento either cannot write there or tries to store its cache in the system /...
Fiasco Labs's user avatar
  • 7,573
11 votes
Accepted

Magento 2 : Event Observer Exception Not Showing in Screen

I search some more things on this and finaly found my solution, I need to just change the observer code like this. app\code\Vendor\Extension\Observer\RemovecartbeforeObserver.php use Magento\...
Dhiren Vasoya's user avatar
10 votes
Accepted

Magento 2: 'Invalid sender data' While sending custom Email

Try with below code, public function senderEmail($type = null, $storeId = null) { $sender ['email'] = $this->scopeConfig->getValue( self::...
Rakesh Jesadiya's user avatar
10 votes

Category error : Item (Magento\Catalog\Model\Category\Interceptor) with the same ID "191" already exists

Delete records from 'url_rewrite' table where "entity_type" is "category". run php bin/magento indexer:reindex
Nilesh Gosai's user avatar
  • 1,115
10 votes

Why there are commands missing in bin/magento?

In my case I was setting up a new server and had copied the database over from a development site. Although I had an app/etc/env.php file and it was pointing at the correct db, it was missing the ...
Andrew Kett's user avatar
  • 3,478
10 votes
Accepted

M 2.3.4 - "Infinite loop detected..." exception on OPC, how to get items in the cart?

Getting items directly from session was causing this error so I only got quote id from session and then used CartRepositoryInterface to retrieve items. $session = $objectManager->get('\Magento\...
Alan's user avatar
  • 917
9 votes
Accepted

Custom Exceptions for module for Magento 2

I can't guarantee that it's the best solution but when reading the source code of Magento 2 core files most modules do it this way: Create a new folder called Exception in your module's directory. ...
FaHu's user avatar
  • 238
9 votes

Magento 2: Requested store is not found

This generally happens whenever config.php and the database get out of sync. For example, whenever I import a database back to my local development environment. Here were the steps I used to ...
Silas Palmer's user avatar
9 votes
Accepted

Magento 2.3: temando.CRITICAL: "accountID" is required. Enter and try again

Please run the below commands and try again: php bin/magento module:disable Temando_Shipping rm -rf var/cache/ generated/code pub/static/frontend pub/static/adminhtml php bin/magento setup:upgrade php ...
Sumit's user avatar
  • 4,825
8 votes

Category error : Item (Magento\Catalog\Model\Category\Interceptor) with the same ID "191" already exists

The following SQL query cleans up duplicate category rewrites. Do not use without a backup. You can use n98-magerun2 db:console or any other mysql client: delete from url_rewrite where ...
Alex's user avatar
  • 13.7k
8 votes

Why there are commands missing in bin/magento?

Some commands became available only after installation. The mentioned exception appears once you try to run such commands before installation. Probably you missed installing Magento.
yaronish's user avatar
  • 788
8 votes

Magento2.2 - - Failed to read session data

This issue can fixed by increase max_concurrency. It will relate to your traffic and server conditions. In my case i'm able to solved this problem by increase max_concurrency from 6 to 24 This is ...
Yustian's user avatar
  • 123
8 votes
Accepted

Magento 2.3.2 throws DOMXPath exception in backend ("Stores > Configuration") after upgrade from 2.2.7

This issue might be generated due to wrong XML configuration. Kindly check your customize module and third-party module. Check di.xml, events.xml,system.xml and router.xml file in your modules.
Arunprabakaran M's user avatar
7 votes

'Area code not set' issue in custom CLI commands in Magento 2

In magento 2 if you set AreaCode but still get this error then please try following code. Use Magento\Framework\App\Bootstrap; include app/bootstrap.php; $bootstrap = Bootstrap::create(BP, $_SERVER); ...
rakesh prajapati's user avatar
7 votes

Magento2 custom module overrides layout: The element "checkout.cart.item.renderers" already has a child with alias "simple" in exception log

My version override based of method getItemRenderer of Magento\Checkout\Block\Cart\AbstractCart, used variable OverriddenTemplates. file vendor/module/view/frontend/layout/...
Vitalii's user avatar
  • 598
7 votes
Accepted

How should I define and use a custom module Exception?

Are there any rules for how I should do it? Yes. If you take a look at app/Mage.php in the exception() method, you will see that it looks for an exception that matches the pattern $module . '...
scrowler's user avatar
  • 2,014
7 votes
Accepted

Magento2 custom collection invalid method exception

Try to get collection the following way: $productCollection = $this->agencyProductFactory->create() ->getCollection()->addFieldToFilter('zw_agency_product_id', 1);
Sohel Rana's user avatar
  • 35.5k
7 votes
Accepted

Exception usage in magento2

Magento throw, \Magento\Framework\Exception\AlreadyExistsException error type when we have we have tried to a new account on an existing email address. $result = $connection->fetchOne($select, $...
Amit Bera's user avatar
  • 77.1k
6 votes

'Area code not set' issue in custom CLI commands in Magento 2

for this areaCode issue, if the 'frontend' parameter is not working, try : $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL); was working for me, hope it helps
DependencyHell's user avatar
6 votes

Exception handling in Magento 2

Magento2 has different types of Exception handlers, for example: StateException InputException InvalidEmailOrPasswordException MailException NotFoundException ValidatorException Etc. All handler ...
Amit Bera's user avatar
  • 77.1k
6 votes

Magento 2: 'Invalid sender data' While sending custom Email

The problem comes from your setFrom method. I suggest you try to replace: ->setFrom($adminAmail) With: ->setFrom([ 'email' => $this->scopeConfig->getValue(self::EMAIL_TEMPLATE, ...
Raphael at Digital Pianism's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible