Skip to content

Commit

Permalink
Improve error when accessing unsupported mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
greschd committed Oct 3, 2024
1 parent b1927c0 commit e255c9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ansys/acp/core/_server/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import dataclasses
import os
import pathlib
import subprocess
from typing import TextIO

Expand Down Expand Up @@ -103,6 +104,10 @@ def start(self) -> None:
stdout_file = self._config.stdout_file
stderr_file = self._config.stderr_file

binary = pathlib.Path(self._config.binary_path)
if not binary.exists():
raise FileNotFoundError(f"Binary not found: '{binary}'")

Check warning on line 109 in src/ansys/acp/core/_server/direct.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/acp/core/_server/direct.py#L107-L109

Added lines #L107 - L109 were not covered by tests

port = find_free_ports()[0]
self._url = f"localhost:{port}"
self._stdout = open(stdout_file, mode="w", encoding="utf-8")
Expand Down
9 changes: 9 additions & 0 deletions src/ansys/acp/core/_tree_objects/_grpc_helpers/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Any, Concatenate, Generic, TypeVar

from grpc import Channel
from packaging.version import parse as parse_version
from typing_extensions import ParamSpec, Self

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

def collection_property(self: ParentT) -> MutableMapping[CreatableValueT]:
if object_class._SUPPORTED_SINCE is not None and self._server_version is not None:
if self._server_version < parse_version(object_class._SUPPORTED_SINCE):
raise RuntimeError(

Check warning on line 308 in src/ansys/acp/core/_tree_objects/_grpc_helpers/mapping.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/acp/core/_tree_objects/_grpc_helpers/mapping.py#L307-L308

Added lines #L307 - L308 were not covered by tests
f"The '{object_class.__name__}' object is only supported since version "
f"{object_class._SUPPORTED_SINCE} of the ACP gRPC server. The current server version is "
f"{self._server_version}."
)

return MutableMapping._initialize_with_cache(
server_wrapper=self._server_wrapper,
collection_path=CollectionPath(
Expand Down

0 comments on commit e255c9d

Please sign in to comment.