From 1d43651c38c667c0519fb31333ea9c6d67b34547 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Sun, 18 Aug 2024 08:34:54 +0200 Subject: [PATCH] fix: Remove dangerous --continue-on-error flag Signed-off-by: provokateurin --- generate-spec | 6 ++++-- merge-specs | 4 ++++ src/Logger.php | 12 +++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/generate-spec b/generate-spec index 1018c2d..1ca19f5 100755 --- a/generate-spec +++ b/generate-spec @@ -41,7 +41,6 @@ $command ->option('--first-content-type', 'Only output the first content type') ->option('--allow-missing-docs', 'Allow missing documentation fields') ->option('--no-tags', 'Use no tags') - ->option('--continue-on-error', 'Continue on error') ->option('--openapi-version', 'OpenAPI version to use', null, '3.0.3') ->option('--verbose', 'Verbose logging') ->parse($_SERVER["argv"]); @@ -52,7 +51,6 @@ $firstStatusCode = $command->firstStatusCode ?? false; $firstContentType = $command->firstContentType ?? false; $allowMissingDocs = $command->allowMissingDocs ?? false; $useTags = $command->tags ?? true; -Logger::$exitOnError = !($command->continueOnError ?? false); Logger::$verbose = $command->verbose ?? false; $openapiVersion = $command->openapiVersion ?? '3.0.3'; @@ -1026,3 +1024,7 @@ foreach ($scopePaths as $scope => $paths) { Logger::info('app', 'Generated scope ' . $scope . ' with ' . $pathsCount . ' routes!'); } + +if (Logger::$errorCount > 0) { + Logger::panic('app', 'Encountered ' . Logger::$errorCount . ' errors that need to be fixed!'); +} diff --git a/merge-specs b/merge-specs index 1326da2..5c75043 100755 --- a/merge-specs +++ b/merge-specs @@ -171,3 +171,7 @@ function rewriteOperations(array $spec): array { } file_put_contents($mergedSpecPath, json_encode($data, Helpers::jsonFlags()) . "\n"); + +if (Logger::$errorCount > 0) { + Logger::panic('app', 'Encountered ' . Logger::$errorCount . ' errors that need to be fixed!'); +} diff --git a/src/Logger.php b/src/Logger.php index b3fd860..24f68b9 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -3,8 +3,8 @@ namespace OpenAPIExtractor; class Logger { - public static bool $exitOnError = true; public static bool $verbose = false; + public static int $errorCount = 0; protected static function log(LoggerLevel $level, string $context, string $text): void { print(self::format($level, $context, $text)); @@ -34,15 +34,9 @@ public static function warning(string $context, string $text): void { self::log(LoggerLevel::Warning, $context, $text); } - /** - * @throws LoggerException - */ public static function error(string $context, string $text): void { - if (self::$exitOnError) { - throw new LoggerException(LoggerLevel::Error, $context, $text); - } else { - self::log(LoggerLevel::Error, $context, $text); - } + self::$errorCount++; + self::log(LoggerLevel::Error, $context, $text); } /**