Skip to content

Commit d017af6

Browse files
committed
Merge pull request #243 from magento-tango/MAGETWO-36096
[Tango] S50 Exceptions
2 parents c316821 + c7fbad1 commit d017af6

File tree

52 files changed

+686
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+686
-277
lines changed

app/code/Magento/Catalog/Model/Entity/Attribute.php

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ public function __construct(
139139
* Processing object before save data
140140
*
141141
* @return \Magento\Framework\Model\AbstractModel
142-
* @throws \Magento\Eav\Exception
142+
* @throws \Magento\Framework\Exception\LocalizedException
143143
*/
144144
public function beforeSave()
145145
{
146146
try {
147147
$this->attrLockValidator->validate($this);
148148
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
149-
throw new \Magento\Eav\Exception(__($exception->getMessage()));
149+
throw new \Magento\Framework\Exception\LocalizedException(__($exception->getMessage()));
150150
}
151151

152152
$this->setData('modulePrefix', self::MODULE_NAME);

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public function __construct(\Magento\Framework\Stdlib\String $string)
4444
*
4545
* @param Product $object
4646
* @return bool
47-
* @throws \Magento\Eav\Exception
47+
* @throws \Magento\Framework\Exception\LocalizedException
4848
* @throws \Magento\Framework\Exception\LocalizedException
4949
*/
5050
public function validate($object)
5151
{
5252
$attrCode = $this->getAttribute()->getAttributeCode();
5353
$value = $object->getData($attrCode);
5454
if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
55-
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode));
55+
throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
5656
}
5757

5858
if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ protected function _getCurrentConfigFileInfo()
181181
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
182182
* @return $this
183183
* @throws LocalizedException
184+
* @throws \Exception
184185
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
185186
*/
186187
public function validateUserValue($values)
@@ -222,9 +223,6 @@ public function validateUserValue($values)
222223
$value = $this->validatorFile->setProduct($this->getProduct())
223224
->validate($this->_getProcessingParams(), $option);
224225
$this->setUserValue($value);
225-
} catch (\Magento\Framework\Exception\File\LargeSizeException $largeSizeException) {
226-
$this->setIsValid(false);
227-
throw new LocalizedException(__($largeSizeException->getMessage()));
228226
} catch (ProductException $e) {
229227
switch ($this->getProcessMode()) {
230228
case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL:
@@ -236,7 +234,7 @@ public function validateUserValue($values)
236234
}
237235
} catch (\Magento\Framework\Validator\Exception $e) {
238236
$this->setUserValue(null);
239-
} catch (\Magento\Framework\Exception\File\ValidatorException $e) {
237+
} catch (LocalizedException $e) {
240238
$this->setIsValid(false);
241239
throw new LocalizedException(__($e->getMessage()));
242240
} catch (\Exception $e) {

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Product;
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Catalog\Model\Product\Exception as ProductException;
12+
use Magento\Framework\Exception\LocalizedException;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -89,10 +90,12 @@ public function setProduct(Product $product)
8990
* @param \Magento\Framework\Object $processingParams
9091
* @param \Magento\Catalog\Model\Product\Option $option
9192
* @return array
92-
* @throws \Magento\Framework\Exception\LocalizedException
93-
* @throws \Zend_File_Transfer_Exception
93+
* @throws LocalizedException
94+
* @throws ProductException
95+
* @throws \Exception
96+
* @throws \Magento\Framework\Exception\InputException
9497
* @throws \Magento\Framework\Validator\Exception
95-
* @throws \Magento\Catalog\Model\Product\Exception
98+
* @throws \Zend_File_Transfer_Exception
9699
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
97100
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
98101
*/
@@ -116,7 +119,7 @@ public function validate($processingParams, $option)
116119
// when file exceeds the upload_max_filesize, $_FILES is empty
117120
if ($this->validateContentLength()) {
118121
$value = $this->fileSize->getMaxFileSizeInMb();
119-
throw new \Magento\Framework\Exception\File\LargeSizeException(
122+
throw new LocalizedException(
120123
__('The file you uploaded is larger than %1 Megabytes allowed by server', $value)
121124
);
122125
} else {
@@ -188,12 +191,10 @@ public function validate($processingParams, $option)
188191
$errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option);
189192

190193
if (count($errors) > 0) {
191-
throw new \Magento\Framework\Exception\File\ValidatorException(__(implode("\n", $errors)));
194+
throw new LocalizedException(__(implode("\n", $errors)));
192195
}
193196
} else {
194-
throw new \Magento\Framework\Exception\File\ValidatorException(
195-
__('Please specify the product\'s required option(s).')
196-
);
197+
throw new LocalizedException(__('Please specify the product\'s required option(s).'));
197198
}
198199
return $userValue;
199200
}

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ protected function calcRuleProductPrice($ruleData, $productData = null)
562562
* @param int $websiteId
563563
* @param int|null $productId
564564
* @return \Zend_Db_Statement_Interface
565-
* @throws \Magento\Eav\Exception
565+
* @throws \Magento\Framework\Exception\LocalizedException
566566
*/
567567
protected function getRuleProductsStmt($websiteId, $productId = null)
568568
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Model\View\Layout;
7+
8+
use Magento\Framework\App\State;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Psr\Log\LoggerInterface as Logger;
11+
12+
/**
13+
* Layout plugin that handle exceptions
14+
*/
15+
class Plugin
16+
{
17+
/**
18+
* @var State
19+
*/
20+
protected $appState;
21+
22+
/**
23+
* @var \Psr\Log\LoggerInterface
24+
*/
25+
protected $logger;
26+
27+
/**
28+
* @param State $appState
29+
* @param Logger $logger
30+
*/
31+
public function __construct(
32+
State $appState,
33+
Logger $logger
34+
) {
35+
$this->appState = $appState;
36+
$this->logger = $logger;
37+
}
38+
39+
/**
40+
* @param \Magento\Framework\View\Layout $subject
41+
* @param callable $proceed
42+
* @param string $name
43+
* @return string
44+
* @throws \Exception
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function aroundRenderNonCachedElement(\Magento\Framework\View\Layout $subject, \Closure $proceed, $name)
48+
{
49+
$result = '';
50+
try {
51+
$result = $proceed($name);
52+
} catch (\Exception $e) {
53+
if ($this->appState->getMode() === State::MODE_DEVELOPER) {
54+
throw $e;
55+
}
56+
$message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage();
57+
$this->logger->critical($message);
58+
}
59+
return $result;
60+
}
61+
}

app/code/Magento/Developer/etc/di.xml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<type name="Magento\Framework\View\TemplateEngineFactory">
1111
<plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/>
1212
</type>
13+
<type name="Magento\Framework\View\Layout">
14+
<plugin name="exception_handler" type="Magento\Developer\Model\View\Layout\Plugin" sortOrder="10"/>
15+
</type>
1316
<type name="Magento\Framework\View\Result\Page">
1417
<arguments>
1518
<argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument>

app/code/Magento/Eav/Exception.php

-10
This file was deleted.

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

100644100755
+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
1515
use Magento\Framework\App\Config\Element;
1616
use Magento\Framework\Model\AbstractModel;
17-
use Magento\Eav\Exception as EavException;
17+
use Magento\Framework\Exception\LocalizedException;
1818
use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor;
1919
use Magento\Framework\Model\Resource\Db\TransactionManagerInterface;
2020

@@ -334,12 +334,12 @@ public function setType($type)
334334
* Retrieve current entity config
335335
*
336336
* @return Type
337-
* @throws EavException
337+
* @throws LocalizedException
338338
*/
339339
public function getEntityType()
340340
{
341341
if (empty($this->_type)) {
342-
throw new EavException(__('Entity is not initialized'));
342+
throw new LocalizedException(__('Entity is not initialized'));
343343
}
344344
return $this->_type;
345345
}
@@ -372,7 +372,7 @@ public function getTypeId()
372372
*
373373
* @param array|string|null $attributes
374374
* @return $this
375-
* @throws EavException
375+
* @throws LocalizedException
376376
*/
377377
public function unsetAttributes($attributes = null)
378378
{
@@ -387,7 +387,7 @@ public function unsetAttributes($attributes = null)
387387
}
388388

389389
if (!is_array($attributes)) {
390-
throw new EavException(__('Unknown parameter'));
390+
throw new LocalizedException(__('Unknown parameter'));
391391
}
392392

393393
foreach ($attributes as $attrCode) {

app/code/Magento/Eav/Model/Entity/Attribute.php

100644100755
+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\Entity;
77

8-
use Magento\Eav\Exception as EavException;
8+
use Magento\Framework\Exception\LocalizedException;
99
use Magento\Framework\Api\AttributeValueFactory;
1010

1111
/**
@@ -213,15 +213,15 @@ public function loadEntityAttributeIdBySet()
213213
* Prepare data for save
214214
*
215215
* @return $this
216-
* @throws EavException
216+
* @throws LocalizedException
217217
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
218218
* @SuppressWarnings(PHPMD.NPathComplexity)
219219
*/
220220
public function beforeSave()
221221
{
222222
// prevent overriding product data
223223
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
224-
throw new EavException(
224+
throw new LocalizedException(
225225
__(
226226
'The attribute code \'%1\' is reserved by system. Please try another attribute code',
227227
$this->_data['attribute_code']
@@ -240,7 +240,7 @@ public function beforeSave()
240240
['max' => self::ATTRIBUTE_CODE_MAX_LENGTH]
241241
)
242242
) {
243-
throw new EavException(
243+
throw new LocalizedException(
244244
__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)
245245
);
246246
}
@@ -252,7 +252,7 @@ public function beforeSave()
252252
$numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL);
253253
$defaultValue = $numberFormatter->parse($defaultValue);
254254
if ($defaultValue === false) {
255-
throw new EavException(__('Invalid default decimal value'));
255+
throw new LocalizedException(__('Invalid default decimal value'));
256256
}
257257
$this->setDefaultValue($defaultValue);
258258
}
@@ -275,7 +275,7 @@ public function beforeSave()
275275
$defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format);
276276
$this->setDefaultValue($defaultValue);
277277
} catch (\Exception $e) {
278-
throw new EavException(__('Invalid default date'));
278+
throw new LocalizedException(__('Invalid default date'));
279279
}
280280
}
281281
}

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

100644100755
+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Eav\Model\Entity\Attribute;
88

9-
use Magento\Eav\Exception as EavException;
9+
use Magento\Framework\Exception\LocalizedException;
1010
use Magento\Framework\Api\AttributeValueFactory;
1111

1212
/**
@@ -181,7 +181,7 @@ protected function _construct()
181181
* @param string|int|\Magento\Eav\Model\Entity\Type $entityType
182182
* @param string $code
183183
* @return $this
184-
* @throws EavException
184+
* @throws LocalizedException
185185
*/
186186
public function loadByCode($entityType, $code)
187187
{
@@ -195,7 +195,7 @@ public function loadByCode($entityType, $code)
195195
$entityTypeId = $entityType->getId();
196196
}
197197
if (empty($entityTypeId)) {
198-
throw new EavException(__('Invalid entity supplied'));
198+
throw new LocalizedException(__('Invalid entity supplied'));
199199
}
200200
$this->_getResource()->loadByCode($this, $entityTypeId, $code);
201201
$this->_afterLoad();
@@ -461,7 +461,7 @@ public function getEntityIdField()
461461
* Retrieve backend instance
462462
*
463463
* @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
464-
* @throws EavException
464+
* @throws LocalizedException
465465
*/
466466
public function getBackend()
467467
{
@@ -471,7 +471,7 @@ public function getBackend()
471471
}
472472
$backend = $this->_universalFactory->create($this->getBackendModel());
473473
if (!$backend) {
474-
throw new EavException(__('Invalid backend model specified: ' . $this->getBackendModel()));
474+
throw new LocalizedException(__('Invalid backend model specified: ' . $this->getBackendModel()));
475475
}
476476
$this->_backend = $backend->setAttribute($this);
477477
}
@@ -500,7 +500,7 @@ public function getFrontend()
500500
* Retrieve source instance
501501
*
502502
* @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
503-
* @throws EavException
503+
* @throws LocalizedException
504504
*/
505505
public function getSource()
506506
{
@@ -510,7 +510,7 @@ public function getSource()
510510
}
511511
$source = $this->_universalFactory->create($this->getSourceModel());
512512
if (!$source) {
513-
throw new EavException(
513+
throw new LocalizedException(
514514
__(
515515
'Source model "%1" not found for attribute "%2"',
516516
$this->getSourceModel(),

app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\Entity\Attribute\Backend;
77

8-
use Magento\Eav\Exception as EavException;
8+
use Magento\Framework\Exception\LocalizedException;
99

1010
/**
1111
* Entity/Attribute/Model - attribute backend abstract
@@ -214,7 +214,7 @@ public function getDefaultValue()
214214
*
215215
* @param \Magento\Framework\Object $object
216216
* @return bool
217-
* @throws EavException
217+
* @throws LocalizedException
218218
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
219219
*/
220220
public function validate($object)
@@ -223,7 +223,7 @@ public function validate($object)
223223
$attrCode = $attribute->getAttributeCode();
224224
$value = $object->getData($attrCode);
225225
if ($attribute->getIsVisible() && $attribute->getIsRequired() && $attribute->isValueEmpty($value)) {
226-
throw new EavException(__('The value of attribute "%1" must be set', $attrCode));
226+
throw new LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
227227
}
228228

229229
if ($attribute->getIsUnique()
@@ -236,7 +236,7 @@ public function validate($object)
236236
if ($attribute->getIsUnique()) {
237237
if (!$attribute->getEntity()->checkAttributeUniqueValue($attribute, $object)) {
238238
$label = $attribute->getFrontend()->getLabel();
239-
throw new EavException(__('The value of attribute "%1" must be unique', $label));
239+
throw new LocalizedException(__('The value of attribute "%1" must be unique', $label));
240240
}
241241
}
242242

0 commit comments

Comments
 (0)