Exceptions
siapy.core.exceptions
¶
Exceptions for SiaPy library.
This module defines custom exceptions used throughout the SiaPy library to handle errors related to file handling, input validation, processing, and configuration.
SiapyError
¶
Bases: Exception
Base exception for SiaPy library.
This is the base exception class for all custom exceptions in the SiaPy library. All other SiaPy exceptions inherit from this class.
This is the base initialization method for all SiaPy custom exceptions. It stores the error message and component name for detailed error reporting.
PARAMETER | DESCRIPTION |
---|---|
message
|
The error message describing what went wrong.
TYPE:
|
name
|
The name of the library/component raising the error. Defaults to "SiaPy".
TYPE:
|
Example
from siapy.core.exceptions import SiapyError
raise SiapyError("Something went wrong", "MyComponent")
Source code in siapy/core/exceptions.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
InvalidFilepathError
¶
Bases: SiapyError
Exception raised when a required file is not found.
This exception is raised when attempting to access a file that does not exist or when a provided file path is invalid.
Creates an exception for when a required file cannot be found or accessed. The filename is converted to string format for consistent error messaging.
PARAMETER | DESCRIPTION |
---|---|
filename
|
The path to the file that was not found. Can be a string or Path object. |
Example
from siapy.core.exceptions import InvalidFilepathError
from pathlib import Path
# Using string path
raise InvalidFilepathError("/path/to/missing/file.txt")
# Using Path object
raise InvalidFilepathError(Path("missing_file.txt"))
Source code in siapy/core/exceptions.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
InvalidInputError
¶
Bases: SiapyError
Exception raised for invalid input.
This exception is raised when the provided input value does not meet the expected criteria or validation rules.
Creates an exception for when input validation fails. The input value is stored for debugging purposes and included in the error message.
PARAMETER | DESCRIPTION |
---|---|
input_value
|
The invalid input value that caused the error.
TYPE:
|
message
|
Custom error message. Defaults to "Invalid input".
TYPE:
|
Example
from siapy.core.exceptions import InvalidInputError
# With default message
raise InvalidInputError(-5)
# With custom message
raise InvalidInputError(-5, "Value must be non-negative")
Source code in siapy/core/exceptions.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
InvalidTypeError
¶
InvalidTypeError(
input_value: Any,
allowed_types: type | tuple[type, ...],
message: str = "Invalid type",
)
Bases: SiapyError
Exception raised for invalid type.
This exception is raised when a value has an incorrect type that doesn't match the expected or allowed types for a particular operation.
Creates an exception for type validation failures. Stores the actual value, its type, and the allowed types for comprehensive error reporting.
PARAMETER | DESCRIPTION |
---|---|
input_value
|
The value with the invalid type.
TYPE:
|
allowed_types
|
The type or tuple of types that are allowed for this value. |
message
|
Custom error message. Defaults to "Invalid type".
TYPE:
|
Example
from siapy.core.exceptions import InvalidTypeError
# Single allowed type
raise InvalidTypeError("text", int, "Expected integer")
# Multiple allowed types
raise InvalidTypeError("text", (int, float), "Expected numeric type")
Source code in siapy/core/exceptions.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
ProcessingError
¶
ProcessingError(
message: str = "An error occurred during processing",
)
Bases: SiapyError
Exception raised for errors during processing.
This exception is raised when an error occurs during data processing operations, such as image processing, data transformation, or computational tasks.
Creates an exception for when errors occur during data processing operations. This is a general-purpose exception for computational or transformation failures.
PARAMETER | DESCRIPTION |
---|---|
message
|
Error message describing the processing failure. Defaults to "An error occurred during processing".
TYPE:
|
Example
from siapy.core.exceptions import ProcessingError
# With default message
raise ProcessingError()
# With custom message
raise ProcessingError("Failed to process image data")
Source code in siapy/core/exceptions.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
ConfigurationError
¶
ConfigurationError(message: str = 'Configuration error')
Bases: SiapyError
Exception raised for configuration errors.
This exception is raised when there are issues with configuration settings, invalid configuration parameters, or missing required configuration values.
Creates an exception for configuration-related issues such as invalid settings, missing required parameters, or malformed configuration data.
PARAMETER | DESCRIPTION |
---|---|
message
|
Error message describing the configuration issue. Defaults to "Configuration error".
TYPE:
|
Example
from siapy.core.exceptions import ConfigurationError
# With default message
raise ConfigurationError()
# With custom message
raise ConfigurationError("Missing required parameter 'api_key'")
Source code in siapy/core/exceptions.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
MethodNotImplementedError
¶
Bases: SiapyError
Exception raised for not implemented methods.
This exception is raised when a method that should be implemented in a subclass has not been implemented, typically in abstract base classes or interfaces.
Creates an exception for when a required method has not been implemented, typically in abstract base classes or interface implementations.
PARAMETER | DESCRIPTION |
---|---|
class_name
|
The name of the class where the method is not implemented.
TYPE:
|
method_name
|
The name of the method that is not implemented.
TYPE:
|
Example
from siapy.core.exceptions import MethodNotImplementedError
class AbstractProcessor:
def process(self):
raise MethodNotImplementedError("AbstractProcessor", "process")
Source code in siapy/core/exceptions.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
DirectInitializationError
¶
DirectInitializationError(class_: type)
Bases: SiapyError
Exception raised when a class method is required to create an instance.
This exception is raised when attempting to directly instantiate a class that requires the use of specific class methods for proper initialization.
Creates an exception for when a class requires the use of specific class methods for instantiation rather than direct initialization. Automatically discovers available class methods to suggest in the error message.
PARAMETER | DESCRIPTION |
---|---|
class_
|
The class type that cannot be directly initialized.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the required utility function cannot be imported. |
Example
from siapy.core.exceptions import DirectInitializationError
class SpecialClass:
def __init__(self):
raise DirectInitializationError(SpecialClass)
@classmethod
def from_file(cls, filepath):
return cls.__new__(cls)
Source code in siapy/core/exceptions.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|