Permalink
Browse files

Adding in better error handling for CSS files. If they fail to compil…

…e, the cache file will now be deleted. Also the exceptions should now be caught.
  • Loading branch information...
Cody Lundquist
Cody Lundquist committed Apr 16, 2013
1 parent 7f96809 commit 3a4988cc7f7307894272259d8db1328c448b1b57
Showing with 26 additions and 4 deletions.
  1. +20 −3 src/Munee/Asset/Type/Css.php
  2. +6 −1 src/Munee/Dispatcher.php
@@ -8,9 +8,11 @@
namespace Munee\Asset\Type;
use Munee\ErrorException;
use Munee\Utils;
use Munee\Asset\Type;
use lessc;
use scssc;
/**
* Handles CSS
@@ -72,18 +74,33 @@ protected function checkCache($originalFile, $cacheFile)
*
* @param string $originalFile
* @param string $cacheFile
*
* @throws ErrorException
*/
protected function beforeFilter($originalFile, $cacheFile)
{
if ($this->isLess($originalFile)) {
$less = new lessc();
$compiledLess = $less->cachedCompile($originalFile);
try {
$compiledLess = $less->cachedCompile($originalFile);
} catch (\Exception $e) {
// Remove the Cache File because it hasn't been properly compiled yet
unlink($cacheFile);
throw new ErrorException('Error in LESS Compiler', 0, $e);
}
$compiledLess['compiled'] = $this->fixRelativeImagePaths($compiledLess['compiled'], $originalFile);
file_put_contents($cacheFile, serialize($compiledLess));
} elseif ($this->isScss($originalFile)) {
$scss = new \scssc();
$scss = new scssc();
$scss->addImportPath(pathinfo($originalFile, PATHINFO_DIRNAME));
$compiled = $scss->compile(file_get_contents($originalFile));
try {
$compiled = $scss->compile(file_get_contents($originalFile));
} catch (\Exception $e) {
// Remove the Cache File because it hasn't been properly compiled yet
unlink($cacheFile);
throw new ErrorException('Error in SCSS Compiler', 0, $e);
}
$content = compact('compiled');
$parsedFiles = $scss->getParsedFiles();
$parsedFiles[] = $originalFile;
View
@@ -91,7 +91,12 @@ public static function run(Request $Request, $options = array())
$headerController->headerField('Status', '404 Not Found');
return 'Error: ' . $e->getMessage();
} catch (ErrorException $e) {
return 'Error: ' . $e->getMessage();
$errors = 'Error: ' . $e->getMessage();
while ($e = $e->getPrevious()) {
$errors .= "<br>" . $e->getMessage();
}
return $errors;
}
}
}

0 comments on commit 3a4988c

Please sign in to comment.