-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions and environment
- Magento version 2.4.4-p6
Steps to reproduce
You need to have the $_COOKIE['store']
to be an array and not contain a valid store code.
I don't know exactly how to set it this way but Magento code is written to handle that situation as you can see here:
After seeing the fatal error popping up in our logs, I had to manually do : $_COOKIE['store'] = ['test'];
to replicate the bug.
Expected result
The Invalid store parameter. (https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Store/Model/StoreResolver.php#L110) should be thrown
Actual result
A PHP fatal error is triggered:
PHP message: PHP Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, Magento\\Framework\\Phrase given in /var/www/source/vendor/magento/module-store/Model/StoreResolver.php:110
Additional information
Reason is the PHP InvalidArgumentException does not accept a \Magento\Framework\Phrase but only a string.
Here's the bug fix I used to get rid of the error:
diff --git a/src/magento/module-store/Model/StoreResolver.php b/src/magento/module-store/Model/StoreResolver.php
index 2a950b699a..0da28d2760 100644
--- a/module-store/Model/StoreResolver.php
+++ b/module-store/Model/StoreResolver.php
@@ -107,7 +107,7 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
if (is_array($storeCode)) {
if (!isset($storeCode['_data']['code'])) {
- throw new \InvalidArgumentException(__('Invalid store parameter.'));
+ throw new \Magento\Framework\Exception\InvalidArgumentException(__('Invalid store parameter.'));
}
$storeCode = $storeCode['_data']['code'];
}
Note that there's another way of fixing it like this:
diff --git a/src/third-party/magento/module-store/Model/StoreResolver.php b/src/third-party/magento/module-store/Model/StoreResolver.php
index 2a950b699a..0da28d2760 100644
--- a/module-store/Model/StoreResolver.php
+++ b/module-store/Model/StoreResolver.php
@@ -107,7 +107,7 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
if (is_array($storeCode)) {
if (!isset($storeCode['_data']['code'])) {
- throw new \InvalidArgumentException(__('Invalid store parameter.'));
+ throw new \InvalidArgumentException('Invalid store parameter.');
}
$storeCode = $storeCode['_data']['code'];
}
I guess it's up to you guys.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.