Skip to content

Commit 16dd0e4

Browse files
committed
better error reporting when execution of SQL fails because of temporary db creation errors
1 parent ea0a111 commit 16dd0e4

File tree

5 files changed

+6297
-6
lines changed

5 files changed

+6297
-6
lines changed

app/src/Command/DatabaseManagingCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ abstract class DatabaseManagingCommand extends SQLExecutingCommand
1111
* @param array[] $dbSpecList key: db name (as used to identify configured databases), value: array('user': mandatory, 'dbname': mandatory, 'password': mandatory)
1212
* @return array 'succeeded': int, 'failed': int, 'results': same format as dbConfigurationManager::getInstanceConfiguration
1313
* @throws \Exception
14+
*
15+
* @todo make it easier to report back to the caller the errors that prevented creation of any DB
1416
*/
1517
protected function createDatabases($instanceList, $dbSpecList)
1618
{
@@ -37,6 +39,11 @@ function ($schemaManager, $instanceName) use ($dbSpecList) {
3739
/// (this could be achieved by copying the 'dbname' member over the 'servicename' one, or unsetting 'servicename'...)
3840
$finalData = [];
3941
foreach($results['data'] as $instanceName => $data) {
42+
// check for failure in creation of temp db
43+
// @todo how can we tell apart correctly errors that actually prevented the db from being created from other errors?
44+
if (is_array($data) && isset($data['exitcode']) && $data['exitcode'] != 0) {
45+
continue;
46+
}
4047
$dbConnectionSpec = $dbSpecList[$instanceName];
4148
$finalData[$instanceName] = $instanceList[$instanceName];
4249
$finalData[$instanceName]['dbname'] = $dbConnectionSpec['dbname'];

app/src/Command/SQLExecutingCommand.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ protected function executeSqlAction($instanceList, $actionName, $getSqlActionCal
182182
$results[$instanceName] = call_user_func($callable);
183183
$succeeded++;
184184
} catch (\Throwable $t) {
185+
$results[$instanceName] = [
186+
'exitcode' => $t->getCode(),
187+
'stderr' => $t->getMessage(),
188+
];
185189
$failed++;
186190
$this->writeErrorln("\n<error>$actionName in instance '$instanceName' failed! Reason: " . $t->getMessage() . "</error>\n", OutputInterface::VERBOSITY_NORMAL);
187191
}
@@ -201,8 +205,11 @@ protected function executeSqlAction($instanceList, $actionName, $getSqlActionCal
201205
try {
202206
$output = call_user_func_array($outputFilters[$instanceName], [$output, $executors[$instanceName]]);
203207
} catch (\Throwable $t) {
204-
/// @todo shall we reset $result to null or not?
205-
//$result = null;
208+
$output = [
209+
// q: shall we add to the results the sql output ?
210+
'exitcode' => $t->getCode(),
211+
'stderr' => $t->getMessage(),
212+
];
206213
$failed++;
207214
$succeeded--;
208215
$this->writeErrorln("\n<error>$actionName in instance '$instanceName' failed! Reason: " . $t->getMessage() . "</error>\n", OutputInterface::VERBOSITY_NORMAL);
@@ -212,14 +219,14 @@ protected function executeSqlAction($instanceList, $actionName, $getSqlActionCal
212219
$succeeded++;
213220
} else {
214221
$err = trim($process->getErrorOutput());
222+
// some command-line database tools mix up stdout and stderr - we go out of our way to accommodate them...
223+
if ($err === '') {
224+
$err = trim($process->getOutput());
225+
}
215226
$results[$instanceName] = [
216227
'exitcode' => $process->getExitCode(),
217228
'stderr' => $err,
218229
];
219-
// some command-line database tools mix up stdout and stderr - we go out of our way to accommodate them...
220-
if ($err === '') {
221-
$results[$instanceName]['stdout'] = $err = trim($process->getOutput());
222-
}
223230

224231
$failed++;
225232
$this->writeErrorln("\n<error>$actionName in instance '$instanceName' failed! Reason: " . $err . "</error>\n", OutputInterface::VERBOSITY_NORMAL);

app/src/Command/SqlExecute.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
146146

147147
foreach($instanceList as $instanceName => $instanceSpecs) {
148148
if (!isset($dbConnectionSpecs[$instanceName])) {
149+
/// @todo retrieve the actual temp db creation error instead of doing this...
150+
$results['data'][$instanceName] = [
151+
'exitcode' => '1',
152+
'stderr' => 'Error in creation of temporary database'
153+
];
149154
unset($instanceList[$instanceName]);
150155
}
151156
}

0 commit comments

Comments
 (0)