Skip to content

Commit 54f8fe3

Browse files
committed
Handle error message during storage backend init better
1 parent ca17924 commit 54f8fe3

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/aiida/manage/configuration/config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,14 @@ def create_profile(
526526
)
527527

528528
LOGGER.report('Initialising the storage backend.')
529-
profile.storage_cls.initialise(profile)
530529
try:
530+
# not sure if scope is good, at least put it in log
531531
#with contextlib.redirect_stdout(io.StringIO()):
532-
#profile.storage_cls.initialise(profile)
533-
pass
532+
profile.storage_cls.initialise(profile)
534533
except Exception as exception:
535534
raise StorageMigrationError(
536-
f'Storage backend initialisation failed, probably because the configuration is incorrect:\n{exception}'
537-
) from exception
535+
f'During initialisation of storage backend. Please check above traceback for cause.'
536+
)
538537
LOGGER.report('Storage initialisation completed.')
539538

540539
self.add_profile(profile)

tests/manage/configuration/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ def test_create_profile_raises(config_with_profile, monkeypatch, entry_points):
445445
config = config_with_profile
446446
profile_name = uuid.uuid4().hex
447447

448-
def raise_storage_migration_error(*args, **kwargs):
449-
raise exceptions.StorageMigrationError()
448+
def raise_storage_migration_error(*_, **__):
449+
raise exceptions.StorageMigrationError("Monkey patchted error")
450450

451451
monkeypatch.setattr(SqliteTempBackend, 'initialise', raise_storage_migration_error)
452452
entry_points.add(InvalidBaseStorage, 'aiida.storage:core.invalid_base')
@@ -460,7 +460,7 @@ def raise_storage_migration_error(*args, **kwargs):
460460
with pytest.raises(ValueError, match=r'The entry point `.*` could not be loaded'):
461461
config.create_profile(profile_name, 'core.non_existant', {})
462462

463-
with pytest.raises(exceptions.StorageMigrationError, match='Storage backend initialisation failed.*'):
463+
with pytest.raises(exceptions.StorageMigrationError, match='During initialisation of storage backend. Please check above traceback for cause.*'):
464464
config.create_profile(profile_name, 'core.sqlite_temp', {})
465465

466466

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Test container initialization."""
2+
import psutil, os
3+
4+
def test_file_descriptor_closed(aiida_profile):
5+
"""Checks if the number of open file descriptors change during a reset."""
6+
def list_open_file_descriptors():
7+
process = psutil.Process(os.getpid())
8+
return process.open_files()
9+
# We have some connections active due to aiida profile during the first
10+
# reset these are destroyed. We check the second time changes the number of
11+
# open file descriptors.
12+
# TODO The fix should keep the existing connections alive and just reuse them
13+
# then one does not need to do two resets.
14+
aiida_profile.reset_storage()
15+
open_file_descriptors_before = list_open_file_descriptors()
16+
aiida_profile.reset_storage()
17+
open_file_descriptors_after = list_open_file_descriptors()
18+
assert len(open_file_descriptors_before) == len(open_file_descriptors_after), f"Before these file descriptor were open:\n{open_file_descriptors_before}\n Now these are open:\n{open_file_descriptors_after}"

0 commit comments

Comments
 (0)