Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make the invalid diff mode error message understandable #1078

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Console/Command/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
use KevinGH\Box\Phar\PharInfo;
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Filesystem\Path;
use ValueError;
use Webmozart\Assert\Assert;
use function array_map;
use function explode;
Expand Down Expand Up @@ -268,7 +270,23 @@ private static function getDiffMode(IO $io): DiffMode
return DiffMode::FILE_NAME;
}

return DiffMode::from($io->getOption(self::DIFF_OPTION)->asNonEmptyString());
$rawDiffOption = $io->getOption(self::DIFF_OPTION)->asNonEmptyString();

try {
return DiffMode::from($rawDiffOption);
} catch (ValueError) {
// Rethrow a more user-friendly error message
throw new RuntimeException(
sprintf(
'Invalid diff mode "%s". Expected one of: "%s".',
$rawDiffOption,
implode(
'", "',
DiffMode::values(),
),
),
);
}
}

private static function getChecksumAlgorithm(IO $io): string
Expand Down
Loading