97 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 $...
user avatar
45 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 ...
user avatar
  • 11.6k
33 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 $...
user avatar
22 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 ...
user avatar
21 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 ...
user avatar
19 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 ...
user avatar
12 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 /...
user avatar
  • 7,573
12 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 = $...
user avatar
  • 3,386
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\...
user avatar
11 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 ...
user avatar
  • 1,241
10 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->...
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::...
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
user avatar
  • 1,075
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 ...
user avatar
  • 3,438
9 votes

There was an error processing your order. Please contact us or try again later - Paypal

I would say this is your error: PayPal NVP CURL connection error #28: Operation timed out after 30000 milliseconds with 0 bytes received And I would interpret as PayPal is not reachable. Maybe ...
user avatar
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. ...
user avatar
  • 238
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 ...
user avatar
  • 4,695
9 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\...
user avatar
  • 898
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 ...
user avatar
  • 14.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.
user avatar
  • 788
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/...
user avatar
  • 588
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 . '...
user avatar
  • 1,974
7 votes

Exception handling in Magento 2

Magento2 has different types of Exception handlers, for example: StateException InputException InvalidEmailOrPasswordException MailException NotFoundException ValidatorException Etc. All handler ...
user avatar
  • 75.7k
7 votes
Accepted

Magento2 custom collection invalid method exception

Try to get collection following way: $productCollection = $this->agencyProductFactory ->create()->getCollection()->addFieldToFilter('zw_agency_product_id', 1);
user avatar
  • 34.3k
6 votes
Accepted

How Mage::throwException($error) working in below code?

The throw happens when there are elements in the $this->_importErrors array. These errors are not cause by throwing exceptions but by checks like making sure we have enough rows to import. if ($...
user avatar
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
user avatar
6 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); ...
user avatar
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, ...
user avatar
6 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 ...
user avatar
6 votes

Magento 2: Same ID already exists

We have just had the same issue and it's due to the review_entity_summary table having duplicate records for that product id. if you select * from review_entity_summary where entity_pk_value='519'; ...
user avatar

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