LessCompiler: Show more details for parsing exceptions
This commit is contained in:
parent
bb196d4a4f
commit
8d047b6ffd
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Util\LessParser;
|
use Icinga\Util\LessParser;
|
||||||
|
|
||||||
|
@ -249,10 +250,38 @@ class LessCompiler
|
||||||
$this->source .= file_get_contents($this->themeMode);
|
$this->source .= file_get_contents($this->themeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return preg_replace(
|
try {
|
||||||
'/(\.icinga-module\.module-[^\s]+) (#layout\.[^\s]+)/m',
|
return preg_replace(
|
||||||
'\2 \1',
|
'/(\.icinga-module\.module-[^\s]+) (#layout\.[^\s]+)/m',
|
||||||
$this->lessc->compile($this->source)
|
'\2 \1',
|
||||||
);
|
$this->lessc->compile($this->source)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$excerpt = substr($this->source, $e->index - 500, 1000);
|
||||||
|
|
||||||
|
$lines = [];
|
||||||
|
$found = false;
|
||||||
|
$pos = $e->index - 500;
|
||||||
|
foreach (explode("\n", $excerpt) as $i => $line) {
|
||||||
|
if ($i === 0) {
|
||||||
|
$pos += strlen($line);
|
||||||
|
$lines[] = '.. ' . $line;
|
||||||
|
} else {
|
||||||
|
$pos += strlen($line) + 1;
|
||||||
|
$sep = ' ';
|
||||||
|
if (! $found && $pos > $e->index) {
|
||||||
|
$found = true;
|
||||||
|
$sep = '!! ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines[] = $sep . $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines[] = '..';
|
||||||
|
$excerpt = join("\n", $lines);
|
||||||
|
|
||||||
|
return sprintf("%s\n%s\n\n\n%s", $e->getMessage(), $e->getTraceAsString(), $excerpt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue