From 16309c540ced7d6db6ddb10ab5df0208efc4bef6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 13 Aug 2023 09:00:05 +0200 Subject: [PATCH] Support handling of rector fatal errors (#111) --- lib/CsFixerResult.php | 7 +++++++ lib/RectorResult.php | 7 +++++++ pages/apply.php | 9 +++++++++ pages/preview.php | 9 +++++++++ 4 files changed, 32 insertions(+) diff --git a/lib/CsFixerResult.php b/lib/CsFixerResult.php index b6f319ac9..c1ce2302e 100644 --- a/lib/CsFixerResult.php +++ b/lib/CsFixerResult.php @@ -51,4 +51,11 @@ public function getFileDiffs(): array } return $fileDiffs; } + + /** + * @return list + */ + public function getFatalErrors(): array { + return []; + } } diff --git a/lib/RectorResult.php b/lib/RectorResult.php index 2c6452838..a5a613316 100644 --- a/lib/RectorResult.php +++ b/lib/RectorResult.php @@ -71,4 +71,11 @@ public function getAppliedRectors(): array return array_unique($rectors); } + + /** + * @return list + */ + public function getFatalErrors(): array { + return $this->json['fatal_errors'] ?? []; + } } diff --git a/pages/apply.php b/pages/apply.php index e19fa86c6..604522090 100644 --- a/pages/apply.php +++ b/pages/apply.php @@ -24,6 +24,15 @@ $result = RexFactor::runRexFactor($addon, $setList, $targetVersion, false, $skipList->toRectorSkipList()); +$fatalErrors = $result->getFatalErrors(); +if ($fatalErrors !== []) { + foreach($fatalErrors as $error) { + echo rex_view::error($error); + } + + return; +} + $total = $result->getTotals(); $content = ''; if ($total['changed_files'] > 0) { diff --git a/pages/preview.php b/pages/preview.php index c560be180..4e5aa130a 100644 --- a/pages/preview.php +++ b/pages/preview.php @@ -52,6 +52,15 @@ $result = RexFactor::runRexFactor($addon, $setList, $targetVersion, true, $skipList->toRectorSkipList()); +$fatalErrors = $result->getFatalErrors(); +if ($fatalErrors !== []) { + foreach($fatalErrors as $error) { + echo rex_view::error($error); + } + + return; +} + $html = $content = $diffout = ''; $total = $result->getTotals(); if ($total['changed_files'] > 0) {