From 02ef2546c808c82cfe2317944e4d8b79d3f9d283 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 30 Jun 2017 11:55:49 +0200 Subject: [PATCH] Handle errors. --- bin/database-to-plantuml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/database-to-plantuml b/bin/database-to-plantuml index 2f33765..8586e26 100755 --- a/bin/database-to-plantuml +++ b/bin/database-to-plantuml @@ -111,7 +111,21 @@ if (empty($databaseName)) { exit(2); } -$reader = new Frontend\Reader($databaseDsn, $databaseUser, $databasePassword); -$backend = new $backendName(); +try { + $reader = new Frontend\Reader($databaseDsn, $databaseUser, $databasePassword); + $backend = new $backendName(); -echo $backend->visit($reader->read($databaseName)); + echo $backend->visit($reader->read($databaseName)); +} catch (Exception $e) { + ob_start(); + + Console\Cursor::colorize('foreground(white) background(red)'); + echo $e->getMessage(), "\n"; + Console\Cursor::colorize('normal'); + $content = ob_get_contents(); + + ob_end_clean(); + + file_put_contents('php://stderr', $content); + exit(2); +}