Skip to content

Commit e255c9d

Browse files
committed
Improve error when accessing unsupported mapping
1 parent b1927c0 commit e255c9d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ansys/acp/core/_server/direct.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import dataclasses
2424
import os
25+
import pathlib
2526
import subprocess
2627
from typing import TextIO
2728

@@ -103,6 +104,10 @@ def start(self) -> None:
103104
stdout_file = self._config.stdout_file
104105
stderr_file = self._config.stderr_file
105106

107+
binary = pathlib.Path(self._config.binary_path)
108+
if not binary.exists():
109+
raise FileNotFoundError(f"Binary not found: '{binary}'")
110+
106111
port = find_free_ports()[0]
107112
self._url = f"localhost:{port}"
108113
self._stdout = open(stdout_file, mode="w", encoding="utf-8")

src/ansys/acp/core/_tree_objects/_grpc_helpers/mapping.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing import Any, Concatenate, Generic, TypeVar
2727

2828
from grpc import Channel
29+
from packaging.version import parse as parse_version
2930
from typing_extensions import ParamSpec, Self
3031

3132
from ansys.api.acp.v0.base_pb2 import CollectionPath, DeleteRequest, ListRequest
@@ -302,6 +303,14 @@ def define_mutable_mapping(
302303
"""Define a mutable mapping of child tree objects."""
303304

304305
def collection_property(self: ParentT) -> MutableMapping[CreatableValueT]:
306+
if object_class._SUPPORTED_SINCE is not None and self._server_version is not None:
307+
if self._server_version < parse_version(object_class._SUPPORTED_SINCE):
308+
raise RuntimeError(
309+
f"The '{object_class.__name__}' object is only supported since version "
310+
f"{object_class._SUPPORTED_SINCE} of the ACP gRPC server. The current server version is "
311+
f"{self._server_version}."
312+
)
313+
305314
return MutableMapping._initialize_with_cache(
306315
server_wrapper=self._server_wrapper,
307316
collection_path=CollectionPath(

0 commit comments

Comments
 (0)