-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
86 lines (61 loc) · 2.32 KB
/
exceptions.py
File metadata and controls
86 lines (61 loc) · 2.32 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Runtime exceptions
"""
from __future__ import annotations
from typing import Any, Callable, Optional
class CompiledExtensionNotFoundError(ImportError):
"""
Raised when a compiled extension can't be imported i.e. found
"""
def __init__(self, compiled_extension_name: str):
error_msg = f"Could not find compiled extension {compiled_extension_name!r}"
super().__init__(error_msg)
class FortranError(Exception):
"""
Base class for errors that originated on the Fortran side
"""
class MissingOptionalDependencyError(ImportError):
"""
Raised when an optional dependency is missing
For example, plotting dependencies like matplotlib
"""
def __init__(self, callable_name: str, requirement: str) -> None:
"""
Initialise the error
Parameters
----------
callable_name
The name of the callable that requires the dependency
requirement
The name of the requirement
"""
error_msg = f"`{callable_name}` requires {requirement} to be installed"
super().__init__(error_msg)
class WrapperError(ValueError):
"""
Base exception for errors that arise from wrapper functionality
"""
class NotInitialisedError(WrapperError):
"""
Raised when the wrapper around the Fortran module hasn't been initialised yet
"""
def __init__(self, instance: Any, method: Optional[Callable[..., Any]] = None):
if method:
error_msg = f"{instance} must be initialised before {method} is called"
else:
error_msg = f"instance ({instance:r}) is not initialised yet"
super().__init__(error_msg)
# TODO: change or even remove this when we move to better error handling
class UnallocatedMemoryError(ValueError):
"""
Raised when we try to access memory that has not yet been allocated
We can't always catch this error, but this is what we raise when we can.
"""
def __init__(self, variable_name: str):
error_msg = (
f"The memory required to access `{variable_name}` is unallocated. "
"You must allocate it before trying to access its value. "
"Unfortunately, we cannot provide more information "
"about why this memory is not yet allocated."
)
super().__init__(error_msg)