1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Command\internal; |
6
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\BaseLiner\BaseLineImportException; |
8
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common\SarbException; |
9
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\File\FileAccessException; |
10
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryAnalyserException; |
11
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\ResultsParser\AnalysisResultsImportException; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Throwable; |
14
|
|
|
|
15
|
|
|
class ErrorReporter |
16
|
|
|
{ |
17
|
|
|
public static function reportError(OutputInterface $output, Throwable $throwable): int |
18
|
|
|
{ |
19
|
|
|
try { |
20
|
|
|
throw $throwable; |
21
|
|
|
} catch (InvalidConfigException $e) { |
22
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
23
|
|
|
|
24
|
|
|
return 11; |
25
|
|
|
} catch (BaseLineImportException $e) { |
26
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
27
|
|
|
|
28
|
|
|
return 12; |
29
|
|
|
} catch (AnalysisResultsImportException $e) { |
30
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
31
|
|
|
|
32
|
|
|
return 13; |
33
|
|
|
} catch (FileAccessException $e) { |
34
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
35
|
|
|
|
36
|
|
|
return 14; |
37
|
|
|
} catch (HistoryAnalyserException $e) { |
38
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
39
|
|
|
|
40
|
|
|
return 15; |
41
|
|
|
} catch (Throwable $e) { |
42
|
|
|
// This should never happen. All exceptions should extend SarbException |
43
|
|
|
OutputWriter::writeToStdError($output, "Unexpected critical error: {$e->getMessage()}", true); |
44
|
|
|
|
45
|
|
|
return 100; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|