Skip to content

Commit 517788a

Browse files
committed
Handle the error properly when LESS source file is empty or having compilation error, and make the error message clear and clean.
1 parent 20db8f6 commit 517788a

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

app/code/Magento/Deploy/Package/Package.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@ public function getFilesByType($type)
320320
*/
321321
public function deleteFile($fileId)
322322
{
323+
$file = $this->files[$fileId];
324+
$deployedFileId = $file->getDeployedFileId();
323325
unset($this->files[$fileId]);
326+
unset($this->map[$deployedFileId]);
324327
}
325328

326329
/**

app/code/Magento/Deploy/Service/DeployPackage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ public function deployEmulated(Package $package, array $options, $skipLogging =
134134
} catch (ContentProcessorException $exception) {
135135
$errorMessage = __('Compilation from source: ')
136136
. $file->getSourcePath()
137-
. PHP_EOL . $exception->getMessage();
137+
. PHP_EOL . $exception->getMessage() . PHP_EOL;
138138
$this->errorsCount++;
139139
$this->logger->critical($errorMessage);
140+
$package->deleteFile($file->getFileId());
140141
} catch (\Exception $exception) {
141142
$this->logger->critical(
142143
'Compilation from source ' . $file->getSourcePath() . ' failed' . PHP_EOL . (string)$exception

dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\State;
1010
use Magento\Framework\App\TemplateTypesInterface;
1111
use Magento\Framework\Phrase;
12+
use Magento\Framework\View\Asset\ContentProcessorInterface;
1213
use Magento\Setup\Module\I18n\Locale;
1314
use Magento\Theme\Block\Html\Footer;
1415

@@ -267,7 +268,7 @@ public function cssDirectiveDataProvider()
267268
'Empty or missing file' => [
268269
TemplateTypesInterface::TYPE_HTML,
269270
'file="css/non-existent-file.css"',
270-
'/* Contents of the specified CSS file could not be loaded or is empty */'
271+
'/*' . PHP_EOL . ContentProcessorInterface::ERROR_MESSAGE_PREFIX . 'LESS file is empty: ',
271272
],
272273
'File with compilation error results in error message' => [
273274
TemplateTypesInterface::TYPE_HTML,

lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function processContent(File $asset)
7777
$content = $this->assetSource->getContent($asset);
7878

7979
if (trim($content) === '') {
80-
return '';
80+
throw new ContentProcessorException(new Phrase(ContentProcessorInterface::ERROR_MESSAGE_PREFIX . 'LESS file is empty: ' . $path));
8181
}
8282

8383
$tmpFilePath = $this->temporaryFile->createFile($path, $content);
@@ -88,8 +88,7 @@ public function processContent(File $asset)
8888
gc_enable();
8989

9090
if (trim($content) === '') {
91-
$this->logger->warning('Parsed less file is empty: ' . $path);
92-
return '';
91+
throw new ContentProcessorException(new Phrase(ContentProcessorInterface::ERROR_MESSAGE_PREFIX . 'LESS file is empty: ' . $path));
9392
} else {
9493
return $content;
9594
}

lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Adapter/Less/ProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function testProcessContentException()
111111

112112
/**
113113
* Test for processContent method (empty content)
114+
*
115+
* @expectedException \Magento\Framework\View\Asset\ContentProcessorException
116+
* @expectedExceptionMessageRegExp (Compilation from source: LESS file is empty: test-path)
114117
*/
115118
public function testProcessContentEmpty()
116119
{

0 commit comments

Comments
 (0)