Skip to content

Commit 1dc2953

Browse files
committed
Don't catch patch exceptions in the command, but let it bubble up to the application so the correct exit code will be generated.
1 parent aceb5ad commit 1dc2953

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/DbPatch/Command/Patch/PHP.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,11 @@ public function apply()
9595
return false;
9696
}
9797

98-
try {
99-
100-
$env = new DbPatch_Command_Patch_PHP_Environment();
101-
$env->setDb($this->getDb()->getAdapter())
102-
->setWriter($this->getWriter())
103-
->setConfig($this->getConfig())
104-
->install($phpFile);
105-
106-
} catch (Exception $e) {
107-
$this->getWriter()->line(sprintf('error php patch: %s', $e->getMessage()));
108-
return false;
109-
}
98+
$env = new DbPatch_Command_Patch_PHP_Environment();
99+
$env->setDb($this->getDb()->getAdapter())
100+
->setWriter($this->getWriter())
101+
->setConfig($this->getConfig())
102+
->install($phpFile);
110103

111104
return true;
112105
}

src/DbPatch/Command/Patch/SQL.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,12 @@ public function apply()
9292
return false;
9393
}
9494

95-
try {
96-
$db = $this->getDb();
97-
$db->import($this->data['filename']);
95+
$db = $this->getDb();
96+
$db->import($this->data['filename']);
9897

99-
// SQLite needs a reconnect after changing scheme
100-
$this->fixSqliteSchemaChangedBug();
98+
// SQLite needs a reconnect after changing scheme
99+
$this->fixSqliteSchemaChangedBug();
101100

102-
} catch (Exception $e) {
103-
$this->writer->error($e->getMessage());
104-
return false;
105-
}
106101
return true;
107102
}
108103

src/DbPatch/Command/Update.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ public function execute()
107107
foreach ($patchFiles as $patchNr => $patchFile)
108108
{
109109
if (($patchFile->patch_number <> $latestPatchNumber + 1) && !$force) {
110-
$this->writer->error(
111-
sprintf('expected patch number %d instead of %d (%s). Use --force to override this check.',
112-
$latestPatchNumber + 1,
113-
$patchFile->patch_number,
114-
$patchFile->basename
110+
throw new DbPatch_Exception(
111+
sprintf(
112+
'expected patch number %d instead of %d (%s). Use --force to override this check.',
113+
$latestPatchNumber + 1,
114+
$patchFile->patch_number,
115+
$patchFile->basename
115116
)
116117
);
117-
return;
118118
}
119119

120120
if (in_array($patchNr, $patchNumbersToSkip)) {
@@ -130,12 +130,11 @@ public function execute()
130130
->apply();
131131

132132
if (!$result) {
133-
return;
133+
throw new DbPatch_Exception(sprintf('Running patch %d failed!', $patchNr));
134134
}
135135

136136
$this->addToChangelog($patchFile);
137137
$latestPatchNumber = $patchFile->patch_number;
138-
139138
}
140139
}
141140

0 commit comments

Comments
 (0)