Skip to content

Commit bdef1f5

Browse files
committed
refactor: rename catalog error classes to include 'Rpc' suffix for clarity and consistency
1 parent 65b0ba0 commit bdef1f5

File tree

11 files changed

+111
-87
lines changed

11 files changed

+111
-87
lines changed
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
from common_library.errors_classes import OsparcErrorMixin
22

33

4-
class CatalogApiBaseError(OsparcErrorMixin, Exception):
4+
class CatalogRpcError(OsparcErrorMixin, Exception):
55
pass
66

77

8-
class CatalogInconsistentError(CatalogApiBaseError):
8+
class CatalogInconsistentRpcError(CatalogRpcError):
99
msg_template = "Catalog is inconsistent: The following services are in the database but missing in the registry manifest {missing_services}"
1010

1111

12-
class CatalogItemNotFoundError(CatalogApiBaseError):
12+
class CatalogItemNotFoundRpcError(CatalogRpcError):
1313
msg_template = "{name} was not found"
1414

1515

16-
class CatalogForbiddenError(CatalogApiBaseError):
16+
class CatalogBatchNotFoundRpcError(CatalogRpcError):
17+
msg_template = "{name} were not found"
18+
19+
20+
class CatalogForbiddenRpcError(CatalogRpcError):
1721
msg_template = "Insufficient access rights for {name}"
1822

1923

20-
class CatalogNotAvailableError(CatalogApiBaseError):
21-
msg_template = "Catalog service failed unexpectedly"
24+
class CatalogNotAvailableRpcError(CatalogRpcError):
25+
msg_template = "Catalog service is currently not available"
2226

2327

24-
class CatalogBadRequestError(CatalogApiBaseError):
28+
class CatalogBadRequestRpcError(CatalogRpcError):
2529
msg_template = "Bad request on {name}: {reason}"

services/api-server/src/simcore_service_api_server/services_rpc/catalog.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from servicelib.rabbitmq import RabbitMQRPCClient
2424
from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc
2525
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import (
26-
CatalogForbiddenError,
27-
CatalogItemNotFoundError,
26+
CatalogForbiddenRpcError,
27+
CatalogItemNotFoundRpcError,
2828
)
2929

3030
from ..exceptions.backend_errors import (
@@ -134,8 +134,8 @@ async def list_all_services_summaries(
134134

135135
@_exception_mapper(
136136
rpc_exception_map={
137-
CatalogItemNotFoundError: ProgramOrSolverOrStudyNotFoundError,
138-
CatalogForbiddenError: ServiceForbiddenAccessError,
137+
CatalogItemNotFoundRpcError: ProgramOrSolverOrStudyNotFoundError,
138+
CatalogForbiddenRpcError: ServiceForbiddenAccessError,
139139
ValidationError: InvalidInputError,
140140
}
141141
)
@@ -156,8 +156,8 @@ async def get(
156156

157157
@_exception_mapper(
158158
rpc_exception_map={
159-
CatalogItemNotFoundError: ProgramOrSolverOrStudyNotFoundError,
160-
CatalogForbiddenError: ServiceForbiddenAccessError,
159+
CatalogItemNotFoundRpcError: ProgramOrSolverOrStudyNotFoundError,
160+
CatalogForbiddenRpcError: ServiceForbiddenAccessError,
161161
ValidationError: InvalidInputError,
162162
}
163163
)

services/catalog/src/simcore_service_catalog/api/rpc/_services.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
from pyinstrument import Profiler
2323
from servicelib.rabbitmq import RPCRouter
2424
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import (
25-
CatalogForbiddenError,
26-
CatalogItemNotFoundError,
25+
CatalogBatchNotFoundRpcError,
26+
CatalogForbiddenRpcError,
27+
CatalogItemNotFoundRpcError,
2728
)
2829

30+
from ...errors import BatchNotFoundError
2931
from ...models.services_db import ServiceDBFilters
3032
from ...repository.groups import GroupsRepository
3133
from ...repository.services import ServicesRepository
@@ -58,7 +60,12 @@ async def _wrapper(app: FastAPI, **kwargs):
5860
return _wrapper
5961

6062

61-
@router.expose(reraise_if_error_type=(CatalogForbiddenError, ValidationError))
63+
@router.expose(
64+
reraise_if_error_type=(
65+
CatalogForbiddenRpcError,
66+
ValidationError,
67+
)
68+
)
6269
@_profile_rpc_call
6370
@validate_call(config={"arbitrary_types_allowed": True})
6471
async def list_services_paginated(
@@ -100,8 +107,8 @@ async def list_services_paginated(
100107

101108
@router.expose(
102109
reraise_if_error_type=(
103-
CatalogItemNotFoundError,
104-
CatalogForbiddenError,
110+
CatalogItemNotFoundRpcError,
111+
CatalogForbiddenRpcError,
105112
ValidationError,
106113
)
107114
)
@@ -134,8 +141,8 @@ async def get_service(
134141

135142
@router.expose(
136143
reraise_if_error_type=(
137-
CatalogItemNotFoundError,
138-
CatalogForbiddenError,
144+
CatalogItemNotFoundRpcError,
145+
CatalogForbiddenRpcError,
139146
ValidationError,
140147
)
141148
)
@@ -171,8 +178,8 @@ async def update_service(
171178

172179
@router.expose(
173180
reraise_if_error_type=(
174-
CatalogItemNotFoundError,
175-
CatalogForbiddenError,
181+
CatalogItemNotFoundRpcError,
182+
CatalogForbiddenRpcError,
176183
ValidationError,
177184
)
178185
)
@@ -198,7 +205,13 @@ async def check_for_service(
198205
)
199206

200207

201-
@router.expose(reraise_if_error_type=(CatalogForbiddenError, ValidationError))
208+
@router.expose(
209+
reraise_if_error_type=(
210+
CatalogForbiddenRpcError,
211+
CatalogBatchNotFoundRpcError,
212+
ValidationError,
213+
)
214+
)
202215
@validate_call(config={"arbitrary_types_allowed": True})
203216
async def batch_get_my_services(
204217
app: FastAPI,
@@ -214,13 +227,20 @@ async def batch_get_my_services(
214227
) -> MyServicesRpcBatchGet:
215228
assert app.state.engine # nosec
216229

217-
batch_got = await catalog_services.batch_get_user_services(
218-
repo=ServicesRepository(app.state.engine),
219-
groups_repo=GroupsRepository(app.state.engine),
220-
product_name=product_name,
221-
user_id=user_id,
222-
ids=ids,
223-
)
230+
try:
231+
232+
batch_got = await catalog_services.batch_get_user_services(
233+
repo=ServicesRepository(app.state.engine),
234+
groups_repo=GroupsRepository(app.state.engine),
235+
product_name=product_name,
236+
user_id=user_id,
237+
ids=ids,
238+
)
239+
240+
except BatchNotFoundError as e:
241+
ctx = e.error_context()
242+
ctx["name"] = f"{ctx.get('missing_services',[])}"
243+
raise CatalogBatchNotFoundRpcError(**ctx) from e
224244

225245
assert [
226246
(sv.key, sv.release.version) for sv in batch_got.found_items
@@ -275,8 +295,8 @@ async def list_my_service_history_latest_first(
275295

276296
@router.expose(
277297
reraise_if_error_type=(
278-
CatalogItemNotFoundError,
279-
CatalogForbiddenError,
298+
CatalogItemNotFoundRpcError,
299+
CatalogForbiddenRpcError,
280300
ValidationError,
281301
)
282302
)
@@ -311,7 +331,7 @@ async def get_service_ports(
311331
]
312332

313333

314-
@router.expose(reraise_if_error_type=(CatalogForbiddenError, ValidationError))
334+
@router.expose(reraise_if_error_type=(CatalogForbiddenRpcError, ValidationError))
315335
@_profile_rpc_call
316336
@validate_call(config={"arbitrary_types_allowed": True})
317337
async def list_all_services_summaries_paginated(
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from common_library.errors_classes import OsparcErrorMixin
22

33

4-
class CatalogBaseError(OsparcErrorMixin, Exception): ...
4+
class BaseCatalogError(OsparcErrorMixin, Exception): ...
55

66

7-
class RepositoryError(CatalogBaseError):
7+
class RepositoryError(BaseCatalogError):
88
msg_template = "Unexpected error in {repo_cls}"
99

1010

1111
class UninitializedGroupError(RepositoryError):
1212
msg_tempalte = "{group} groups was never initialized"
1313

1414

15-
class BaseDirectorError(CatalogBaseError): ...
15+
class BaseDirectorError(BaseCatalogError): ...
1616

1717

1818
class DirectorUnresponsiveError(BaseDirectorError):
@@ -22,5 +22,5 @@ class DirectorUnresponsiveError(BaseDirectorError):
2222
class DirectorStatusError(BaseDirectorError): ...
2323

2424

25-
class CatalogServiceNotFoundError(CatalogBaseError):
26-
msg_template = "One or more services were not found in the catalog. Missing: {missing_services}"
25+
class BatchNotFoundError(BaseCatalogError):
26+
msg_template = "None of the batch services were found in the catalog. Missing: {missing_services}"

services/catalog/src/simcore_service_catalog/service/catalog_services.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
from models_library.users import UserID
2626
from pydantic import HttpUrl
2727
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import (
28-
CatalogForbiddenError,
29-
CatalogInconsistentError,
30-
CatalogItemNotFoundError,
28+
CatalogForbiddenRpcError,
29+
CatalogInconsistentRpcError,
30+
CatalogItemNotFoundRpcError,
3131
)
3232

3333
from ..clients.director import DirectorClient
34-
from ..errors import CatalogServiceNotFoundError
34+
from ..errors import BatchNotFoundError
3535
from ..models.catalog_services import BatchGetUserServicesResult
3636
from ..models.services_db import (
3737
ServiceAccessRightsDB,
@@ -178,7 +178,7 @@ async def _get_services_with_access_rights(
178178
((sc.key, sc.version) for sc in services), product_name=product_name
179179
)
180180
if not access_rights:
181-
raise CatalogForbiddenError(
181+
raise CatalogForbiddenRpcError(
182182
name="any service",
183183
user_id=user_id,
184184
product_name=product_name,
@@ -241,7 +241,7 @@ async def _get_services_manifests(
241241
_logger.warning(
242242
**create_troubleshooting_log_kwargs(
243243
msg,
244-
error=CatalogInconsistentError(
244+
error=CatalogInconsistentRpcError(
245245
missing_services=missing_services,
246246
user_id=user_id,
247247
product_name=product_name,
@@ -414,7 +414,7 @@ async def get_catalog_service(
414414
)
415415
if not service:
416416
# no service found provided `access_rights`
417-
raise CatalogForbiddenError(
417+
raise CatalogForbiddenRpcError(
418418
name=f"{service_key}:{service_version}",
419419
service_key=service_key,
420420
service_version=service_version,
@@ -449,7 +449,7 @@ async def update_catalog_service(
449449
update: ServiceUpdateV2,
450450
) -> ServiceGetV2:
451451
if is_function_service(service_key):
452-
raise CatalogForbiddenError(
452+
raise CatalogForbiddenRpcError(
453453
name=f"function service {service_key}:{service_version}",
454454
service_key=service_key,
455455
service_version=service_version,
@@ -550,7 +550,7 @@ async def check_catalog_service_permissions(
550550
product_name=product_name,
551551
)
552552
if not access_rights:
553-
raise CatalogItemNotFoundError(
553+
raise CatalogItemNotFoundRpcError(
554554
name=f"{service_key}:{service_version}",
555555
service_key=service_key,
556556
service_version=service_version,
@@ -575,7 +575,7 @@ async def check_catalog_service_permissions(
575575
)
576576

577577
if not has_permission:
578-
raise CatalogForbiddenError(
578+
raise CatalogForbiddenRpcError(
579579
name=f"{service_key}:{service_version}",
580580
service_key=service_key,
581581
service_version=service_version,
@@ -611,7 +611,7 @@ async def batch_get_user_services(
611611
key_versions=unique_service_identifiers, product_name=product_name
612612
)
613613
if not services_access_rights:
614-
raise CatalogServiceNotFoundError(
614+
raise BatchNotFoundError(
615615
missing_services=unique_service_identifiers,
616616
user_id=user_id,
617617
product_name=product_name,
@@ -695,7 +695,7 @@ async def batch_get_user_services(
695695
if not found:
696696
# None of the services found
697697
assert len(unique_service_identifiers) == len(missing) # nosec
698-
raise CatalogServiceNotFoundError(
698+
raise BatchNotFoundError(
699699
missing_services=missing,
700700
user_id=user_id,
701701
product_name=product_name,

services/catalog/tests/unit/with_dbs/test_api_rpc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
from servicelib.rabbitmq import RabbitMQRPCClient
3535
from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc
3636
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import (
37-
CatalogForbiddenError,
38-
CatalogItemNotFoundError,
37+
CatalogForbiddenRpcError,
38+
CatalogItemNotFoundRpcError,
3939
)
4040

4141
pytest_simcore_core_services_selection = [
@@ -371,7 +371,7 @@ async def test_rpc_get_service_not_found_error(
371371
user_id: UserID,
372372
):
373373

374-
with pytest.raises(CatalogItemNotFoundError, match="unknown"):
374+
with pytest.raises(CatalogItemNotFoundRpcError, match="unknown"):
375375
await catalog_rpc.get_service(
376376
rpc_client,
377377
product_name=product_name,
@@ -408,7 +408,7 @@ async def test_rpc_check_for_service(
408408
product_name: ProductName,
409409
user_id: UserID,
410410
):
411-
with pytest.raises(CatalogItemNotFoundError, match="unknown"):
411+
with pytest.raises(CatalogItemNotFoundRpcError, match="unknown"):
412412
await catalog_rpc.check_for_service(
413413
rpc_client,
414414
product_name=product_name,
@@ -450,7 +450,7 @@ async def test_rpc_get_service_access_rights(
450450
assert other_user["primary_gid"] not in service.access_rights
451451

452452
# other_user does not have EXECUTE access -----------------
453-
with pytest.raises(CatalogForbiddenError, match=service_key):
453+
with pytest.raises(CatalogForbiddenRpcError, match=service_key):
454454
await catalog_rpc.get_service(
455455
rpc_client,
456456
product_name=product_name,
@@ -460,7 +460,7 @@ async def test_rpc_get_service_access_rights(
460460
)
461461

462462
# other_user does not have WRITE access
463-
with pytest.raises(CatalogForbiddenError, match=service_key):
463+
with pytest.raises(CatalogForbiddenRpcError, match=service_key):
464464
await catalog_rpc.update_service(
465465
rpc_client,
466466
product_name=product_name,
@@ -501,7 +501,7 @@ async def test_rpc_get_service_access_rights(
501501
service_version=service_version,
502502
)
503503

504-
with pytest.raises(CatalogForbiddenError, match=service_key):
504+
with pytest.raises(CatalogForbiddenRpcError, match=service_key):
505505
await catalog_rpc.update_service(
506506
rpc_client,
507507
product_name=product_name,
@@ -760,7 +760,7 @@ async def test_rpc_get_service_ports_not_found(
760760
non_existent_key = "simcore/services/comp/non-existent-service"
761761

762762
# Test service not found scenario
763-
with pytest.raises(CatalogItemNotFoundError, match="non-existent-service"):
763+
with pytest.raises(CatalogItemNotFoundRpcError, match="non-existent-service"):
764764
await catalog_rpc.get_service_ports(
765765
rpc_client,
766766
product_name=product_name,
@@ -811,7 +811,7 @@ async def test_rpc_get_service_ports_permission_denied(
811811
await services_db_tables_injector([fake_restricted_service])
812812

813813
# Attempt to access without permission
814-
with pytest.raises(CatalogForbiddenError):
814+
with pytest.raises(CatalogForbiddenRpcError):
815815
await catalog_rpc.get_service_ports(
816816
rpc_client,
817817
product_name=product_name,

0 commit comments

Comments
 (0)