Repository: hummingbot/hummingbot
Issue: import non-existant file crashes the app

>>> import li

This file doesn't exist. The right hand side complains and leaves a message in the logs. New commands no longer work. We should fail gracefully if a file does not exist and simply notify the user.

```
File "/home/hummingbot/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/hummingbot/hummingbot/client/command/import_command.py", line 38, in import_config_file
    strategy = await update_strategy_config_map_from_file(strategy_path)
  File "/home/hummingbot/hummingbot/client/config/config_helpers.py", line 267, in update_strategy_config_map_from_file
    strategy = strategy_name_from_file(yml_path)
  File "/home/hummingbot/hummingbot/client/config/config_helpers.py", line 249, in strategy_name_from_file
    with open(file_path) as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'conf/li.yml'
```



┆Issue is synchronized with this [Clickup task](https://app.clickup.com/t/1ramk15) by [Unito](https://www.unito.io)


Changed files:
test/hummingbot/client/command/test_import_command.py, hummingbot/client/command/import_command.py

diff --git a/hummingbot/client/command/import_command.py b/hummingbot/client/command/import_command.py
index 85c68d514..5c9dbd605 100644
--- a/hummingbot/client/command/import_command.py
+++ b/hummingbot/client/command/import_command.py
@@ -13,7 +13,7 @@ from hummingbot.client.settings import CONF_PREFIX, STRATEGIES_CONF_DIR_PATH, re
 from hummingbot.core.utils.async_utils import safe_ensure_future
 
 if TYPE_CHECKING:
-    from hummingbot.client.hummingbot_application import HummingbotApplication
+    from hummingbot.client.hummingbot_application import HummingbotApplication  # noqa: F401
 
 
 class ImportCommand:
@@ -39,7 +39,15 @@ class ImportCommand:
             self.app.to_stop_config = False
             return
         strategy_path = STRATEGIES_CONF_DIR_PATH / file_name
-        config_map = await load_strategy_config_map_from_file(strategy_path)
+        try:
+            config_map = await load_strategy_config_map_from_file(strategy_path)
+        except Exception as e:
+            self.notify(f'Strategy import error: {str(e)}')
+            # Reset prompt settings
+            self.placeholder_mode = False
+            self.app.hide_input = False
+            self.app.change_prompt(prompt=">>> ")
+            raise
         self.strategy_file_name = file_name
         self.strategy_name = (
             config_map.strategy
diff --git a/test/hummingbot/client/command/test_import_command.py b/test/hummingbot/client/command/test_import_command.py
index b84811d47..c184cfcb7 100644
--- a/test/hummingbot/client/command/test_import_command.py
+++ b/test/hummingbot/client/command/test_import_command.py
@@ -201,3 +201,30 @@ class ImportCommandTest(unittest.TestCase):
 
         self.assertEqual(1, len(validation_errors))
         self.assertEqual("no_default - field required", validation_errors[0])
+
+    @patch("hummingbot.client.config.config_helpers.get_strategy_pydantic_config_cls")
+    @patch("hummingbot.client.command.status_command.StatusCommand.status_check_all")
+    def test_import_config_file_wrong_name(
+        self, status_check_all_mock: AsyncMock, get_strategy_pydantic_config_cls: MagicMock
+    ):
+        strategy_name = "perpetual_market_making"
+        strategy_file_name = f"{strategy_name}.yml"
+        status_check_all_mock.return_value = True
+        dummy_strategy_config_cls = self.build_dummy_strategy_config_cls(strategy_name)
+        get_strategy_pydantic_config_cls.return_value = dummy_strategy_config_cls
+        cm = ClientConfigAdapter(dummy_strategy_config_cls(no_default="some value"))
+
+        wrong_strategy_file_name = f"wrong-{strategy_file_name}"
+        with TemporaryDirectory() as d:
+            d = Path(d)
+            import_command.STRATEGIES_CONF_DIR_PATH = d
+            temp_file_name = d / strategy_file_name
+            save_to_yml(temp_file_name, cm)
+            try:
+                self.async_run_with_timeout(
+                    self.app.import_config_file(wrong_strategy_file_name))
+            except FileNotFoundError:
+                self.assertNotEqual(strategy_file_name, self.app.strategy_file_name)
+                self.assertNotEqual(strategy_name, self.app.strategy_name)
+                return
+            self.assertTrue(False)