From f406b6134477a63f4655c499dea7f734a2680b83 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 16 Aug 2023 12:21:40 +0100 Subject: [PATCH 1/2] Throw an exception when asking for db information but the container isn't running --- inc/composer/class-command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index bf2e8c11..2b33e413 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -969,6 +969,7 @@ protected function generate_docker_compose( array $args = [] ) : void { /** * Return the Database connection details. * + * @throws \RuntimeException When the database container cannot be found. * @return array */ private function get_db_connection_data() { @@ -1013,6 +1014,10 @@ private function get_db_connection_data() { $ports = shell_exec( sprintf( "$command_prefix docker ps --format '{{.Ports}}' --filter id=%s", $db_container_id ) ); preg_match( '/([\d.]+):([\d]+)->.*/', trim( $ports ), $ports_matches ); + if ( empty( $ports_matches ) ) { + throw new \RuntimeException( 'Could not retrieve information for the database. Is the container running?' ); + } + return array_merge( array_filter( $values ), [ From eda27459ec2072bf7d132ad596a3430df8ffa519 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 16 Aug 2023 12:28:36 +0100 Subject: [PATCH 2/2] Fix indentation --- inc/composer/class-command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 2b33e413..4b8b1346 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -969,7 +969,7 @@ protected function generate_docker_compose( array $args = [] ) : void { /** * Return the Database connection details. * - * @throws \RuntimeException When the database container cannot be found. + * @throws \RuntimeException When the database container cannot be found. * @return array */ private function get_db_connection_data() {