Repository: conan-io/conan

Issue:
[bug] Conan config install list breaks if config file is missing
The PR https://github.com/conan-io/conan/pull/7263 inserts a new feature, which breaks when conan cache is clear.

### Environment Details (include every applicable attribute)
  * Operating System+version: Linux
  * Compiler+version: Any
  * Conan version: 1.27.0-dev
  * Python version: 3.8.1

### Steps to reproduce (Include if Applicable)

1) Set a new (empty) conan cache folder
2) Run `conan config install --list`


### Logs (Executed commands with output) (Include/Attach if Applicable)

```
export CONAN_USER_HOME=/tmp/conan
conan config install --list
Traceback (most recent call last):
  File "/home/uilian/Development/conan/conan/venv/lib/python3.8/site-packages/conans/client/command.py", line 2051, in run
    method(args[0][1:])
  File "/home/uilian/Development/conan/conan/venv/lib/python3.8/site-packages/conans/client/command.py", line 608, in config
    configs = self._conan.config_install_list()
  File "/home/uilian/Development/conan/conan/venv/lib/python3.8/site-packages/conans/client/conan_api.py", line 94, in wrapper
    return f(api, *args, **kwargs)
  File "/home/uilian/Development/conan/conan/venv/lib/python3.8/site-packages/conans/client/conan_api.py", line 607, in config_install_list
    return json.loads(load(self.app.cache.config_install_file))
  File "/home/uilian/Development/conan/conan/venv/lib/python3.8/site-packages/conans/util/files.py", line 218, in load
    with open(path, 'rb') as handle:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/conan/.conan/config_install.json'

ERROR: [Errno 2] No such file or directory: '/tmp/conan/.conan/config_install.json'
```


Discussion:
Please @uilianries submit a fix if possible. Thanks!

Resolving patch:
diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py
--- a/conans/client/conan_api.py
+++ b/conans/client/conan_api.py
@@ -604,10 +604,14 @@ def config_rm(self, item):
 
     @api_method
     def config_install_list(self):
+        if not os.path.isfile(self.app.cache.config_install_file):
+            return []
         return json.loads(load(self.app.cache.config_install_file))
 
     @api_method
     def config_install_remove(self, index):
+        if not os.path.isfile(self.app.cache.config_install_file):
+            raise ConanException("There is no config data. Need to install config first.")
         configs = json.loads(load(self.app.cache.config_install_file))
         try:
             configs.pop(index)


Test patch:
diff --git a/conans/test/functional/command/config_install_test.py b/conans/test/functional/command/config_install_test.py
--- a/conans/test/functional/command/config_install_test.py
+++ b/conans/test/functional/command/config_install_test.py
@@ -550,6 +550,14 @@ def test_list_remove(self):
         self.client.run("config install --list")
         self.assertNotIn("myconfig.zip", self.client.out)
 
+    def test_list_empty_config(self):
+        self.client.run("config install --list")
+        self.assertEqual("", self.client.out)
+
+    def test_remove_empty_config(self):
+        self.client.run("config install --remove=0", assert_error=True)
+        self.assertIn("There is no config data. Need to install config first.", self.client.out)
+
     def test_overwrite_read_only_file(self):
         source_folder = self._create_profile_folder()
         self.client.run('config install "%s"' % source_folder)