Skip to content

Commit 1d7ea38

Browse files
committed
Merge branch 'feature/runner-improve-internal-exception' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 73dafe5 + acbb0b7 commit 1d7ea38

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Runner.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,39 @@ public function processFile($file)
652652
}
653653
} catch (\Exception $e) {
654654
$error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
655+
656+
// Determine which sniff caused the error.
657+
$sniffStack = null;
658+
$nextStack = null;
659+
foreach ($e->getTrace() as $step) {
660+
if (isset($step['file']) === false) {
661+
continue;
662+
}
663+
664+
if (empty($sniffStack) === false) {
665+
$nextStack = $step;
666+
break;
667+
}
668+
669+
if (substr($step['file'], -9) === 'Sniff.php') {
670+
$sniffStack = $step;
671+
continue;
672+
}
673+
}
674+
675+
if (empty($sniffStack) === false) {
676+
if (empty($nextStack) === false
677+
&& isset($nextStack['class']) === true
678+
&& substr($nextStack['class'], -5) === 'Sniff'
679+
) {
680+
$sniffCode = Common::getSniffCode($nextStack['class']);
681+
} else {
682+
$sniffCode = substr(strrchr(str_replace('\\', '/', $sniffStack['file']), '/'), 1);
683+
}
684+
685+
$error .= sprintf(PHP_EOL.'The error originated in the %s sniff on line %s.', $sniffCode, $sniffStack['line']);
686+
}
687+
655688
$file->addErrorOnLine($error, 1, 'Internal.Exception');
656689
}//end try
657690

0 commit comments

Comments
 (0)