diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php
index <HASH>..<HASH> 100644
--- a/system/src/Grav/Common/GPM/GPM.php
+++ b/system/src/Grav/Common/GPM/GPM.php
@@ -323,13 +323,20 @@ class GPM extends Iterator
             return $found;
         }
 
-        foreach ($this->getRepositoryThemes() as $slug => $theme) {
+        $themes = $this->getRepositoryThemes();
+        $plugins = $this->getRepositoryPlugins();
+
+        if (!$themes && !$plugins) {
+            throw new \RuntimeException("GPM not reachable. Please check your internet connection or check the Grav site is reachable");
+        }
+
+        if ($themes) foreach ($themes as $slug => $theme) {
             if ($search == $slug || $search == $theme->name) {
                 return $theme;
             }
         }
 
-        foreach ($this->getRepositoryPlugins() as $slug => $plugin) {
+        if ($plugins) foreach ($plugins as $slug => $plugin) {
             if ($search == $slug || $search == $plugin->name) {
                 return $plugin;
             }
Improve error when trying to install a plugin/theme from the command line and GPM is unreachable

Previously it listed four times `PHP Warning:  Invalid argument
supplied for foreach()...`, now it fails with an error message