-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_exceptions.py
More file actions
150 lines (109 loc) · 4.2 KB
/
_exceptions.py
File metadata and controls
150 lines (109 loc) · 4.2 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
"""Exception hierarchy for JSONLT operations.
This module defines the exception types used throughout the JSONLT library,
following the specification's error categories.
"""
from typing_extensions import override
from ._types import JSONObject, Key
class JSONLTError(Exception):
"""Base exception for all JSONLT operations.
All exceptions raised by JSONLT inherit from this class, allowing
callers to catch all JSONLT-related errors with a single handler.
"""
class ParseError(JSONLTError):
"""Error during parsing of JSONLT content.
Raised for:
- Invalid UTF-8 encoding
- Invalid JSON syntax
- Non-object JSON values where objects are expected
- Duplicate keys in JSON objects
- Invalid $deleted values (not boolean true)
- Header appearing on non-first line
- Invalid header structure
- Missing or invalid version field
See specification section "Parse errors (ParseError)".
"""
class InvalidKeyError(JSONLTError):
"""Error related to keys or key specifiers.
Raised for:
- Missing required key fields in records
- Invalid key field values (null, boolean, object, array)
- Numbers outside the valid integer key range
- Fractional numbers in key fields
- Records containing $-prefixed fields
- Key specifier mismatch between header and caller
- Duplicate field names in key specifier tuples
- Empty key specifier or key tuples
See specification section "Key errors (KeyError)".
"""
class FileError(JSONLTError):
"""Error during file system operations.
Raised for:
- File read failures (permissions, I/O errors)
- File write failures (permissions, I/O errors)
- Atomic file replacement failures
See specification section "File errors (IOError)".
"""
class LockError(JSONLTError):
"""Error during file locking.
Raised when a file lock cannot be acquired within the configured timeout.
See specification section "Lock errors (LockError)".
"""
class LimitError(JSONLTError):
"""Error when content exceeds implementation limits.
Raised for:
- Key length exceeding maximum
- Record size exceeding maximum
- JSON nesting depth exceeding maximum
- Tuple key exceeding maximum element count
See specification section "Limit errors (LimitError)".
"""
class TransactionError(JSONLTError):
"""Error related to transaction operations.
Raised for:
- Attempting to start a nested transaction
See specification section "Transaction errors (TransactionError)".
"""
class ConflictError(TransactionError):
"""Error when a transaction commit detects a write-write conflict.
Raised when another process has modified a key that the transaction
also modified since the transaction started.
See specification section "Transaction errors (TransactionError)".
Attributes:
key: The conflicting key.
expected: The value that was expected (from transaction start snapshot).
actual: The actual current value (after reload).
"""
def __init__(
self,
message: str,
key: "Key",
expected: "JSONObject | None",
actual: "JSONObject | None",
) -> None:
"""Initialize a ConflictError.
Args:
message: The error message.
key: The conflicting key.
expected: The value that was expected (from transaction start).
actual: The actual current value (after reload).
"""
super().__init__(message)
self._key: Key = key
self._expected: JSONObject | None = expected
self._actual: JSONObject | None = actual
@property
def key(self) -> "Key":
"""The conflicting key."""
return self._key
@property
def expected(self) -> "JSONObject | None":
"""The value that was expected (from transaction start snapshot)."""
return self._expected
@property
def actual(self) -> "JSONObject | None":
"""The actual current value (after reload)."""
return self._actual
@override
def __repr__(self) -> str:
"""Return a string representation of the conflict error."""
return f"ConflictError({self.args[0]!r}, key={self._key!r})"