Skip to content

Commit

Permalink
fix: Remove dangerous --continue-on-error flag
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Aug 19, 2024
1 parent cdfedf4 commit 1d43651
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 4 additions & 2 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -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';

Expand Down Expand Up @@ -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!');
}
4 changes: 4 additions & 0 deletions merge-specs
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
12 changes: 3 additions & 9 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 1d43651

Please sign in to comment.