From a2063f8eecb4f059c2d45201da00993e1559fc44 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Wed, 17 Jul 2024 16:10:30 +0200 Subject: [PATCH] CLI: Fix bug `verdi presto` when tab-completing without config (#6535) For a clean environment where the config directory had not yet been created, tab-completing `verdi presto` would result in an exception being thrown because the callable for the default of the `--profile-name` option would try to access the configuration. The exception is now caught and the callable simply returns the default profile name `presto` which should be correct since no profiles should exist if there is not even a configuration directory. --- src/aiida/cmdline/commands/cmd_presto.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/aiida/cmdline/commands/cmd_presto.py b/src/aiida/cmdline/commands/cmd_presto.py index 6fa9518443..83ba287a94 100644 --- a/src/aiida/cmdline/commands/cmd_presto.py +++ b/src/aiida/cmdline/commands/cmd_presto.py @@ -25,9 +25,17 @@ def get_default_presto_profile_name(): + from aiida.common.exceptions import ConfigurationError from aiida.manage import get_config - profile_names = get_config().profile_names + try: + profile_names = get_config().profile_names + except ConfigurationError: + # This can happen when tab-completing in an environment that did not create the configuration folder yet. + # It would have been possible to just call ``get_config(create=True)`` to create the config directory, but this + # should not be done during tab-completion just to generate a default value. + return DEFAULT_PROFILE_NAME_PREFIX + indices = [] for profile_name in profile_names: