Skip to content

Commit

Permalink
Update error message output in ValidateCsv. StdErr to StdOut (#66)
Browse files Browse the repository at this point in the history
Error message outputs have been updated in ValidateCsv class for better
readability and debugging. The method `OutLvl::E` has been removed from
`this->_()` function to streamline the message output, improving the
error message display.
  • Loading branch information
SmetDenis committed Mar 20, 2024
1 parent fa8ed9e commit ceae37d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
namespace JBZoo\CsvBlueprint\Commands;

use JBZoo\Cli\CliCommand;
use JBZoo\Cli\OutLvl;
use JBZoo\CsvBlueprint\Csv\CsvFile;
use JBZoo\CsvBlueprint\Exception;
use JBZoo\CsvBlueprint\Schema;
Expand Down Expand Up @@ -168,7 +167,7 @@ private function validateSchema(string $schemaFilename): ?ErrorSuite
$schemaErrors = (new Schema($schemaFilename))->validate();
if ($schemaErrors->count() > 0) {
$this->_("<red>Schema is invalid:</red> {$schemaFilename}");
$this->_($schemaErrors->render($this->getReportType()), OutLvl::E);
$this->_($schemaErrors->render($this->getReportType()));
}
}

Expand Down Expand Up @@ -199,15 +198,12 @@ private function validateCsvFiles(array $csvFilenames, string $schemaFilename):
$errorCounter += $errorSuite->count();

if ($this->isHumanReadableMode()) {
$this->_(
"{$prefix} <red>Invalid file:</red> " . Utils::cutPath($csvFilename->getPathname()),
OutLvl::E,
);
$this->_("{$prefix} <red>Invalid file:</red> " . Utils::cutPath($csvFilename->getPathname()));
}

$output = $errorSuite->render($this->getOptString('report'));
if ($output !== null) {
$this->_($output, $this->isHumanReadableMode() ? OutLvl::E : OutLvl::DEFAULT);
$this->_($output);
}
} elseif ($this->isHumanReadableMode()) {
$this->_("{$prefix} <green>OK:</green> " . Utils::cutPath($csvFilename->getPathname()));
Expand Down Expand Up @@ -241,7 +237,7 @@ private function printFooter(
$errMessage = "<c>Found {$errorCounter} issues in {$invalidFiles} out of {$totalFiles} CSV files.</c>";
}

$this->_($errMessage, OutLvl::E);
$this->_($errMessage);

$exitCode = self::FAILURE;
}
Expand Down

0 comments on commit ceae37d

Please sign in to comment.