From f1d05d204e5ce788ffcfaed04d3c4a06233eb231 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 15 Apr 2014 18:14:26 +0200 Subject: Use exceptions for in input validation. --- core/command/db/converttype.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'core/command') diff --git a/core/command/db/converttype.php b/core/command/db/converttype.php index 02dc45383e8..6fcaeacec49 100644 --- a/core/command/db/converttype.php +++ b/core/command/db/converttype.php @@ -97,23 +97,24 @@ class ConvertType extends Command { protected function validateInput(InputInterface $input, OutputInterface $output) { $type = $input->getArgument('type'); if ($this->connectionFactory->normalizeType($type) === 'sqlite3') { - $output->writeln('Converting to SQLite (sqlite3) is currently not supported.'); - return 1; + throw new \InvalidArgumentException( + 'Converting to SQLite (sqlite3) is currently not supported.' + ); } if ($type === $this->config->getValue('dbtype', '')) { - $output->writeln(sprintf( - 'Can not convert from %1$s to %1$s.', + throw new \InvalidArgumentException(sprintf( + 'Can not convert from %1$s to %1$s.', $type )); - return 1; } if ($type === 'oci' && $input->getOption('clear-schema')) { // Doctrine unconditionally tries (at least in version 2.3) // to drop sequence triggers when dropping a table, even though // such triggers may not exist. This results in errors like // "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist". - $output->writeln('The --clear-schema option is not supported when converting to Oracle (oci).'); - return 1; + throw new \InvalidArgumentException( + 'The --clear-schema option is not supported when converting to Oracle (oci).' + ); } } @@ -148,11 +149,7 @@ class ConvertType extends Command { } protected function execute(InputInterface $input, OutputInterface $output) { - $inputError = $this->validateInput($input, $output); - if ($inputError) { - return $inputError; - } - + $this->validateInput($input, $output); $this->readPassword($input, $output); $fromDB = \OC_DB::getConnection(); -- cgit v1.2.3