Skip to content

Commit

Permalink
IMPROVE: Clearer error message for unconfigured computers (#4670)
Browse files Browse the repository at this point in the history
Previously the code just raised with a `NotExistent: No result was found`
message, but at the point of failure we can be more explicit about the
cause of the error (the missing configuration step). Now the error is
clearer and provides the solution to the problem.
  • Loading branch information
ramirezfranciscof committed Mar 25, 2021
1 parent 75310e0 commit a8ee41d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,15 @@ def get_authinfo(self, user):
"""
from . import authinfos

return authinfos.AuthInfo.objects(self.backend).get(dbcomputer_id=self.id, aiidauser_id=user.id)
try:
authinfo = authinfos.AuthInfo.objects(self.backend).get(dbcomputer_id=self.id, aiidauser_id=user.id)
except exceptions.NotExistent as exc:
raise exceptions.NotExistent(
f'Computer `{self.label}` (ID={self.id}) not configured for user `{user.get_short_name()}` '
f'(ID={user.id}) - use `verdi computer configure` first'
) from exc

return authinfo

def is_user_configured(self, user):
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/orm/test_computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ def test_configure_ssh_invalid(self):

with self.assertRaises(ValueError):
comp.configure(username='radames', invalid_auth_param='TEST')

def test_non_configure_error(self):
"""Configure a computer for local transport and check it is configured."""
self.comp_builder.label = 'test_non_configure_error'
self.comp_builder.transport = 'local'
comp = self.comp_builder.new()
comp.store()

with self.assertRaises(exceptions.NotExistent) as exc:
comp.get_authinfo(self.user)

self.assertIn(str(comp.id), str(exc.exception))
self.assertIn(comp.label, str(exc.exception))
self.assertIn(self.user.get_short_name(), str(exc.exception))
self.assertIn(str(self.user.id), str(exc.exception))
self.assertIn('verdi computer configure', str(exc.exception))

0 comments on commit a8ee41d

Please sign in to comment.