Skip to content

Commit

Permalink
Merge pull request #243 from magento-tango/MAGETWO-36096
Browse files Browse the repository at this point in the history
[Tango] S50 Exceptions
  • Loading branch information
Dooffy committed Apr 20, 2015
2 parents c316821 + c7fbad1 commit d017af6
Show file tree
Hide file tree
Showing 52 changed files with 686 additions and 277 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Entity/Attribute.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ public function __construct(
* Processing object before save data
*
* @return \Magento\Framework\Model\AbstractModel
* @throws \Magento\Eav\Exception
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeSave()
{
try {
$this->attrLockValidator->validate($this);
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
throw new \Magento\Eav\Exception(__($exception->getMessage()));
throw new \Magento\Framework\Exception\LocalizedException(__($exception->getMessage()));
}

$this->setData('modulePrefix', self::MODULE_NAME);
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public function __construct(\Magento\Framework\Stdlib\String $string)
*
* @param Product $object
* @return bool
* @throws \Magento\Eav\Exception
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function validate($object)
{
$attrCode = $this->getAttribute()->getAttributeCode();
$value = $object->getData($attrCode);
if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode));
throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
}

if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
Expand Down
6 changes: 2 additions & 4 deletions app/code/Magento/Catalog/Model/Product/Option/Type/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ protected function _getCurrentConfigFileInfo()
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return $this
* @throws LocalizedException
* @throws \Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function validateUserValue($values)
Expand Down Expand Up @@ -222,9 +223,6 @@ public function validateUserValue($values)
$value = $this->validatorFile->setProduct($this->getProduct())
->validate($this->_getProcessingParams(), $option);
$this->setUserValue($value);
} catch (\Magento\Framework\Exception\File\LargeSizeException $largeSizeException) {
$this->setIsValid(false);
throw new LocalizedException(__($largeSizeException->getMessage()));
} catch (ProductException $e) {
switch ($this->getProcessMode()) {
case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL:
Expand All @@ -236,7 +234,7 @@ public function validateUserValue($values)
}
} catch (\Magento\Framework\Validator\Exception $e) {
$this->setUserValue(null);
} catch (\Magento\Framework\Exception\File\ValidatorException $e) {
} catch (LocalizedException $e) {
$this->setIsValid(false);
throw new LocalizedException(__($e->getMessage()));
} catch (\Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Catalog\Model\Product\Exception as ProductException;
use Magento\Framework\Exception\LocalizedException;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -89,10 +90,12 @@ public function setProduct(Product $product)
* @param \Magento\Framework\Object $processingParams
* @param \Magento\Catalog\Model\Product\Option $option
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Zend_File_Transfer_Exception
* @throws LocalizedException
* @throws ProductException
* @throws \Exception
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Validator\Exception
* @throws \Magento\Catalog\Model\Product\Exception
* @throws \Zend_File_Transfer_Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand All @@ -116,7 +119,7 @@ public function validate($processingParams, $option)
// when file exceeds the upload_max_filesize, $_FILES is empty
if ($this->validateContentLength()) {
$value = $this->fileSize->getMaxFileSizeInMb();
throw new \Magento\Framework\Exception\File\LargeSizeException(
throw new LocalizedException(
__('The file you uploaded is larger than %1 Megabytes allowed by server', $value)
);
} else {
Expand Down Expand Up @@ -188,12 +191,10 @@ public function validate($processingParams, $option)
$errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option);

if (count($errors) > 0) {
throw new \Magento\Framework\Exception\File\ValidatorException(__(implode("\n", $errors)));
throw new LocalizedException(__(implode("\n", $errors)));
}
} else {
throw new \Magento\Framework\Exception\File\ValidatorException(
__('Please specify the product\'s required option(s).')
);
throw new LocalizedException(__('Please specify the product\'s required option(s).'));
}
return $userValue;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ protected function calcRuleProductPrice($ruleData, $productData = null)
* @param int $websiteId
* @param int|null $productId
* @return \Zend_Db_Statement_Interface
* @throws \Magento\Eav\Exception
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function getRuleProductsStmt($websiteId, $productId = null)
{
Expand Down
61 changes: 61 additions & 0 deletions app/code/Magento/Developer/Model/View/Layout/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Model\View\Layout;

use Magento\Framework\App\State;
use Magento\Framework\Exception\LocalizedException;
use Psr\Log\LoggerInterface as Logger;

/**
* Layout plugin that handle exceptions
*/
class Plugin
{
/**
* @var State
*/
protected $appState;

/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* @param State $appState
* @param Logger $logger
*/
public function __construct(
State $appState,
Logger $logger
) {
$this->appState = $appState;
$this->logger = $logger;
}

/**
* @param \Magento\Framework\View\Layout $subject
* @param callable $proceed
* @param string $name
* @return string
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundRenderNonCachedElement(\Magento\Framework\View\Layout $subject, \Closure $proceed, $name)
{
$result = '';
try {
$result = $proceed($name);
} catch (\Exception $e) {
if ($this->appState->getMode() === State::MODE_DEVELOPER) {
throw $e;
}
$message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage();
$this->logger->critical($message);
}
return $result;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Developer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<type name="Magento\Framework\View\TemplateEngineFactory">
<plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/>
</type>
<type name="Magento\Framework\View\Layout">
<plugin name="exception_handler" type="Magento\Developer\Model\View\Layout\Plugin" sortOrder="10"/>
</type>
<type name="Magento\Framework\View\Result\Page">
<arguments>
<argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument>
Expand Down
10 changes: 0 additions & 10 deletions app/code/Magento/Eav/Exception.php

This file was deleted.

10 changes: 5 additions & 5 deletions app/code/Magento/Eav/Model/Entity/AbstractEntity.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Framework\App\Config\Element;
use Magento\Framework\Model\AbstractModel;
use Magento\Eav\Exception as EavException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor;
use Magento\Framework\Model\Resource\Db\TransactionManagerInterface;

Expand Down Expand Up @@ -334,12 +334,12 @@ public function setType($type)
* Retrieve current entity config
*
* @return Type
* @throws EavException
* @throws LocalizedException
*/
public function getEntityType()
{
if (empty($this->_type)) {
throw new EavException(__('Entity is not initialized'));
throw new LocalizedException(__('Entity is not initialized'));
}
return $this->_type;
}
Expand Down Expand Up @@ -372,7 +372,7 @@ public function getTypeId()
*
* @param array|string|null $attributes
* @return $this
* @throws EavException
* @throws LocalizedException
*/
public function unsetAttributes($attributes = null)
{
Expand All @@ -387,7 +387,7 @@ public function unsetAttributes($attributes = null)
}

if (!is_array($attributes)) {
throw new EavException(__('Unknown parameter'));
throw new LocalizedException(__('Unknown parameter'));
}

foreach ($attributes as $attrCode) {
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Eav/Model/Entity/Attribute.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace Magento\Eav\Model\Entity;

use Magento\Eav\Exception as EavException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Api\AttributeValueFactory;

/**
Expand Down Expand Up @@ -213,15 +213,15 @@ public function loadEntityAttributeIdBySet()
* Prepare data for save
*
* @return $this
* @throws EavException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
throw new EavException(
throw new LocalizedException(
__(
'The attribute code \'%1\' is reserved by system. Please try another attribute code',
$this->_data['attribute_code']
Expand All @@ -240,7 +240,7 @@ public function beforeSave()
['max' => self::ATTRIBUTE_CODE_MAX_LENGTH]
)
) {
throw new EavException(
throw new LocalizedException(
__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)
);
}
Expand All @@ -252,7 +252,7 @@ public function beforeSave()
$numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL);
$defaultValue = $numberFormatter->parse($defaultValue);
if ($defaultValue === false) {
throw new EavException(__('Invalid default decimal value'));
throw new LocalizedException(__('Invalid default decimal value'));
}
$this->setDefaultValue($defaultValue);
}
Expand All @@ -275,7 +275,7 @@ public function beforeSave()
$defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format);
$this->setDefaultValue($defaultValue);
} catch (\Exception $e) {
throw new EavException(__('Invalid default date'));
throw new LocalizedException(__('Invalid default date'));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Magento\Eav\Model\Entity\Attribute;

use Magento\Eav\Exception as EavException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Api\AttributeValueFactory;

/**
Expand Down Expand Up @@ -181,7 +181,7 @@ protected function _construct()
* @param string|int|\Magento\Eav\Model\Entity\Type $entityType
* @param string $code
* @return $this
* @throws EavException
* @throws LocalizedException
*/
public function loadByCode($entityType, $code)
{
Expand All @@ -195,7 +195,7 @@ public function loadByCode($entityType, $code)
$entityTypeId = $entityType->getId();
}
if (empty($entityTypeId)) {
throw new EavException(__('Invalid entity supplied'));
throw new LocalizedException(__('Invalid entity supplied'));
}
$this->_getResource()->loadByCode($this, $entityTypeId, $code);
$this->_afterLoad();
Expand Down Expand Up @@ -461,7 +461,7 @@ public function getEntityIdField()
* Retrieve backend instance
*
* @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
* @throws EavException
* @throws LocalizedException
*/
public function getBackend()
{
Expand All @@ -471,7 +471,7 @@ public function getBackend()
}
$backend = $this->_universalFactory->create($this->getBackendModel());
if (!$backend) {
throw new EavException(__('Invalid backend model specified: ' . $this->getBackendModel()));
throw new LocalizedException(__('Invalid backend model specified: ' . $this->getBackendModel()));
}
$this->_backend = $backend->setAttribute($this);
}
Expand Down Expand Up @@ -500,7 +500,7 @@ public function getFrontend()
* Retrieve source instance
*
* @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
* @throws EavException
* @throws LocalizedException
*/
public function getSource()
{
Expand All @@ -510,7 +510,7 @@ public function getSource()
}
$source = $this->_universalFactory->create($this->getSourceModel());
if (!$source) {
throw new EavException(
throw new LocalizedException(
__(
'Source model "%1" not found for attribute "%2"',
$this->getSourceModel(),
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace Magento\Eav\Model\Entity\Attribute\Backend;

use Magento\Eav\Exception as EavException;
use Magento\Framework\Exception\LocalizedException;

/**
* Entity/Attribute/Model - attribute backend abstract
Expand Down Expand Up @@ -214,7 +214,7 @@ public function getDefaultValue()
*
* @param \Magento\Framework\Object $object
* @return bool
* @throws EavException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function validate($object)
Expand All @@ -223,7 +223,7 @@ public function validate($object)
$attrCode = $attribute->getAttributeCode();
$value = $object->getData($attrCode);
if ($attribute->getIsVisible() && $attribute->getIsRequired() && $attribute->isValueEmpty($value)) {
throw new EavException(__('The value of attribute "%1" must be set', $attrCode));
throw new LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
}

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

Expand Down
Loading

0 comments on commit d017af6

Please sign in to comment.