From 58ecc2458832463726ae575c1f656b8dac28451f Mon Sep 17 00:00:00 2001 From: mscherer Date: Sun, 11 Jan 2026 07:20:10 +0100 Subject: [PATCH] Normalize exception handling in command classes - Remove redundant Exception catch when Throwable already covers it - Use consistent error output formatting with tags - Add verbose trace output to SeedCommand for consistency - Remove unused Exception imports --- src/Command/MigrateCommand.php | 6 ------ src/Command/RollbackCommand.php | 6 ------ src/Command/SeedCommand.php | 7 ++++--- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Command/MigrateCommand.php b/src/Command/MigrateCommand.php index 426645e84..abc73655f 100644 --- a/src/Command/MigrateCommand.php +++ b/src/Command/MigrateCommand.php @@ -19,7 +19,6 @@ use Cake\Console\ConsoleOptionParser; use Cake\Event\EventDispatcherTrait; use DateTime; -use Exception; use LogicException; use Migrations\Config\ConfigInterface; use Migrations\Migration\ManagerFactory; @@ -170,11 +169,6 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int $manager->migrate($version, $fake, $count); } $end = microtime(true); - } catch (Exception $e) { - $io->err('' . $e->getMessage() . ''); - $io->verbose($e->getTraceAsString()); - - return self::CODE_ERROR; } catch (Throwable $e) { $io->err('' . $e->getMessage() . ''); $io->verbose($e->getTraceAsString()); diff --git a/src/Command/RollbackCommand.php b/src/Command/RollbackCommand.php index de33c27ab..d3647f542 100644 --- a/src/Command/RollbackCommand.php +++ b/src/Command/RollbackCommand.php @@ -19,7 +19,6 @@ use Cake\Console\ConsoleOptionParser; use Cake\Event\EventDispatcherTrait; use DateTime; -use Exception; use InvalidArgumentException; use LogicException; use Migrations\Config\ConfigInterface; @@ -183,11 +182,6 @@ protected function executeMigrations(Arguments $args, ConsoleIo $io): ?int $manager->rollback($target, $force, $targetMustMatch, $fake); } $end = microtime(true); - } catch (Exception $e) { - $io->err('' . $e->getMessage() . ''); - $io->verbose($e->getTraceAsString()); - - return self::CODE_ERROR; } catch (Throwable $e) { $io->err('' . $e->getMessage() . ''); $io->verbose($e->getTraceAsString()); diff --git a/src/Command/SeedCommand.php b/src/Command/SeedCommand.php index b7562809b..02726ae72 100644 --- a/src/Command/SeedCommand.php +++ b/src/Command/SeedCommand.php @@ -18,10 +18,10 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Event\EventDispatcherTrait; -use Exception; use Migrations\Config\ConfigInterface; use Migrations\Migration\ManagerFactory; use Migrations\Util\Util; +use Throwable; /** * Seed command runs seeder scripts @@ -166,8 +166,9 @@ protected function executeSeeds(Arguments $args, ConsoleIo $io): ?int // Get all available seeds and ask for confirmation try { $availableSeeds = $manager->getSeeds(); - } catch (Exception $e) { - $io->error('Failed to load seeds: ' . $e->getMessage()); + } catch (Throwable $e) { + $io->err('Failed to load seeds: ' . $e->getMessage() . ''); + $io->verbose($e->getTraceAsString()); return static::CODE_ERROR; }