Skip to content

Commit 5a38a4d

Browse files
authored
Improve error message on inexistent files with local server (#754)
Add a check that the file exists when calling the (no-op) `upload_file` method on the local file transfer strategy. This ensures a nice error is produced when trying to import an inexistent ACPH5 file, instead of failing on H5Open. Resolves #748.
1 parent f784f32 commit 5a38a4d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def __init__(self, working_directory: _PATH) -> None:
5858
self._working_directory = pathlib.Path(working_directory)
5959

6060
def upload_file(self, local_path: _PATH) -> pathlib.Path:
61+
if not pathlib.Path(local_path).exists():
62+
raise FileNotFoundError(f"No such file or directory: '{local_path}'")
6163
return self._get_remote_path(local_path)
6264

6365
def download_file(self, remote_path: _PATH, local_path: _PATH) -> None:

tests/unittests/test_acp_instance.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ def test_import_from_differenct_cwd(acp_instance, model_data_dir):
7575
assert (tmp_dir_path / export_filename).exists()
7676
# Check that the exported file does not exist on the original CWD
7777
assert not pathlib.Path(export_filename).exists()
78+
79+
80+
def test_import_inexistent(acp_instance):
81+
"""Test that inexistent files raise a FileNotFoundError.
82+
83+
Regression test for #748 (when run with 'direct' launch mode).
84+
"""
85+
filename = "inexistent_file.acph5"
86+
with pytest.raises(FileNotFoundError) as exc:
87+
acp_instance.import_model(filename)
88+
assert filename in str(exc.value)

0 commit comments

Comments
 (0)