-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy path__init__.py
More file actions
41 lines (31 loc) · 994 Bytes
/
__init__.py
File metadata and controls
41 lines (31 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pathlib import Path
from ..types import StrOrPath
from .clr_error import ClrError
from .coreclr_errors import get_coreclr_error
from .find import find_dotnet_root
from .hostfxr_errors import get_hostfxr_error
__all__ = [
"check_result",
"find_dotnet_root",
"path_as_string",
"optional_path_as_string",
]
def optional_path_as_string(path: StrOrPath | None) -> str | None:
if path is None:
return None
return path_as_string(path)
def path_as_string(path: StrOrPath) -> str:
return str(Path(path))
def check_result(err_code: int) -> None:
"""Check the error code of a .NET hosting API function and raise a
converted exception.
:raises ClrError: If the error code is `< 0`
"""
if err_code < 0:
hresult = err_code & 0xFFFF_FFFF
error = get_coreclr_error(hresult)
if not error:
error = get_hostfxr_error(hresult)
if not error:
error = ClrError(hresult)
raise error