-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
162 lines (108 loc) · 3.39 KB
/
exceptions.py
File metadata and controls
162 lines (108 loc) · 3.39 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
156
157
158
159
160
161
162
# -*- coding: utf-8 -*-
"""
exceptions.py - Unified exception definitions.
Inspired by `dlubal.api.common.exceptions`.
Usage:
from PySap2000.exceptions import PointError, FrameError, AnalysisError
try:
point = Point.get_by_name(model, "invalid")
except PointError as e:
print(f"Point error: {e}")
print(f"Details: {e.details}")
"""
import warnings
from functools import wraps
from typing import Optional, Dict, Any
def _deprecated_class(cls, replacement: str):
"""Attach a deprecation warning to a legacy exception class."""
original_init = cls.__init__
@wraps(original_init)
def new_init(self, *args, **kwargs):
warnings.warn(
f"{cls.__name__} is deprecated. Use {replacement} instead.",
DeprecationWarning,
stacklevel=2
)
original_init(self, *args, **kwargs)
cls.__init__ = new_init
return cls
class PySap2000Error(Exception):
"""
Base exception for PySap2000.
Attributes:
message: Error message
details: Optional details dictionary
"""
def __init__(self, message: str, details: Optional[Dict[str, Any]] = None):
super().__init__(message)
self.message = message
self.details = details or {}
def __str__(self):
if self.details:
detail_str = ", ".join(f"{k}={v}" for k, v in self.details.items())
return f"{self.message} ({detail_str})"
return self.message
class SAPConnectionError(PySap2000Error):
"""Raised when connecting to SAP2000 fails."""
pass
# Backward-compatible alias. Deprecated; prefer SAPConnectionError.
ConnectionError = SAPConnectionError
class ConnectionTimeoutError(SAPConnectionError):
"""Raised when a SAP2000 connection attempt times out."""
pass
class ConnectionLostError(SAPConnectionError):
"""Raised when an existing SAP2000 connection is lost."""
pass
class SAP2000NotRunningError(SAPConnectionError):
"""Raised when SAP2000 is not running."""
pass
class ObjectError(PySap2000Error):
"""Raised for object operation errors."""
pass
class NodeError(ObjectError):
"""
[DEPRECATED] Point-related error.
Use PointError instead.
"""
pass
NodeError = _deprecated_class(NodeError, "PointError")
class PointError(ObjectError):
"""Raised for point-related errors."""
pass
class MemberError(ObjectError):
"""
[DEPRECATED] Frame-related error.
Use FrameError instead.
"""
pass
MemberError = _deprecated_class(MemberError, "FrameError")
class FrameError(ObjectError):
"""Raised for frame-related errors."""
pass
class SurfaceError(ObjectError):
"""Raised for surface-related errors."""
pass
class AreaError(ObjectError):
"""Raised for area-related errors."""
pass
class CableError(ObjectError):
"""Raised for cable-related errors."""
pass
class LinkError(ObjectError):
"""Raised for link-related errors."""
pass
class MaterialError(ObjectError):
"""Raised for material-related errors."""
pass
class SectionError(ObjectError):
"""Raised for section-related errors."""
pass
class LoadError(ObjectError):
"""Raised for load-related errors."""
pass
class AnalysisError(PySap2000Error):
"""Raised for analysis-related errors."""
pass
class ResultError(PySap2000Error):
"""Raised for result retrieval errors."""
pass