0.1.8
Loading...
Searching...
No Matches
exceptions.py
Go to the documentation of this file.
1"""
2Exception classes for PyHelios library.
3
4This module provides a hierarchy of exceptions that map to various error conditions
5in the Helios C++ core and PyHelios wrapper layer.
6"""
7
8
9class HeliosError(Exception):
10 """Base exception class for all PyHelios-related errors."""
11 pass
12
13
15 """
16 Runtime errors from Helios operations.
17
18 Raised when the Helios core encounters a runtime error condition,
19 such as invalid geometry parameters or numerical precision issues.
20 """
21 pass
22
23
25 """
26 Invalid argument errors.
27
28 Raised when function parameters are invalid, such as null pointers,
29 out-of-range values, or incompatible data types.
30 """
31 pass
32
33
35 """
36 UUID not found errors.
37
38 Raised when attempting to access a primitive or object that doesn't
39 exist in the Context using an invalid UUID.
40 """
41 pass
42
43
45 """
46 File I/O related errors.
47
48 Raised when file operations fail, such as loading PLY files,
49 reading textures, or accessing plugin data files.
50 """
51 pass
52
53
55 """
56 Memory allocation errors.
57
58 Raised when memory allocation fails, typically during large
59 geometry operations or texture loading.
60 """
61 pass
62
63
65 """
66 GPU initialization errors.
67
68 Raised when GPU-related operations fail, such as OptiX initialization
69 for radiation modeling or CUDA setup.
70 """
71 pass
72
73
75 """
76 Plugin not available errors.
77
78 Raised when attempting to use a plugin that is not compiled or
79 available in the current PyHelios installation.
80 """
81 pass
82
83
85 """
86 Unknown errors.
87
88 Raised when an unexpected C++ exception occurs that doesn't
89 map to a specific error category.
90 """
91 pass
92
93
94# Error code to exception mapping
95ERROR_CODE_TO_EXCEPTION = {
96 1: HeliosInvalidArgumentError, # PYHELIOS_ERROR_INVALID_PARAMETER
97 2: HeliosUUIDNotFoundError, # PYHELIOS_ERROR_UUID_NOT_FOUND
98 3: HeliosFileIOError, # PYHELIOS_ERROR_FILE_IO
99 4: HeliosMemoryAllocationError, # PYHELIOS_ERROR_MEMORY_ALLOCATION
100 5: HeliosGPUInitializationError, # PYHELIOS_ERROR_GPU_INITIALIZATION
101 6: HeliosPluginNotAvailableError, # PYHELIOS_ERROR_PLUGIN_NOT_AVAILABLE
102 7: HeliosRuntimeError, # PYHELIOS_ERROR_RUNTIME
103 99: HeliosUnknownError, # PYHELIOS_ERROR_UNKNOWN
104}
105
106
107def create_exception_from_error_code(error_code, error_message):
108 """
109 Create an appropriate exception instance from an error code and message.
110
111 Args:
112 error_code (int): Error code from the C++ wrapper
113 error_message (str): Error message from the C++ wrapper
114
115 Returns:
116 HeliosError: Appropriate exception instance
117 """
118 exception_class = ERROR_CODE_TO_EXCEPTION.get(error_code, HeliosUnknownError)
119 return exception_class(f"Helios error {error_code}: {error_message}")
120
121
122def check_helios_error(get_error_func, get_message_func):
123 """
124 Check for Helios errors and raise appropriate Python exceptions.
125
126 This function is designed to be used as an errcheck callback for ctypes
127 function calls.
128
129 Args:
130 get_error_func: Function to get the last error code
131 get_message_func: Function to get the last error message
132
133 Raises:
134 HeliosError: If an error is detected
135 """
136 error_code = get_error_func()
137 if error_code != 0: # 0 is PYHELIOS_SUCCESS
138 error_message = get_message_func().decode('utf-8') if get_message_func() else "Unknown error"
139 raise create_exception_from_error_code(error_code, error_message)
Exception classes for PyHelios library.
Definition exceptions.py:10
Runtime errors from Helios operations.
Definition exceptions.py:20
check_helios_error(get_error_func, get_message_func)
Check for Helios errors and raise appropriate Python exceptions.
create_exception_from_error_code(error_code, error_message)
Create an appropriate exception instance from an error code and message.