Skip to content

Commit

Permalink
Merge pull request #618 from humanmade/db-info
Browse files Browse the repository at this point in the history
Throw an exception when asking for db information but the container isn't running
  • Loading branch information
mikelittle authored Aug 23, 2023
2 parents 2a2099e + eda2745 commit cdf079c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 ),
[
Expand Down

0 comments on commit cdf079c

Please sign in to comment.