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 DaveLiddament\StaticAnalysisResultsBaseliner\Domain\ResultsParser\ErrorReportedByStaticAnalysisTool; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
final 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 (ErrorReportedByStaticAnalysisTool $e) { |
42
|
|
|
OutputWriter::writeToStdError($output, $e->getMessage(), true); |
43
|
|
|
|
44
|
|
|
return 16; |
45
|
|
|
} catch (\Throwable $e) { |
46
|
|
|
// This should never happen. All exceptions should extend SarbException |
47
|
|
|
OutputWriter::writeToStdError($output, "Unexpected critical error: {$e->getMessage()}", true); |
48
|
|
|
OutputWriter::writeToStdError($output, $e->getTraceAsString(), true); |
49
|
|
|
|
50
|
|
|
return 100; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|