Coverage for src/dataknobs_data/vector/exceptions.py: 50%

26 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-29 14:14 -0600

1"""Vector-specific exceptions.""" 

2 

3from __future__ import annotations 

4 

5 

6class VectorError(Exception): 

7 """Base exception for vector operations.""" 

8 

9 pass 

10 

11 

12class VectorDimensionError(VectorError): 

13 """Raised when vector dimensions don't match expectations.""" 

14 

15 def __init__(self, expected: int, actual: int, field_name: str | None = None): 

16 """Initialize dimension error. 

17 

18 Args: 

19 expected: Expected number of dimensions 

20 actual: Actual number of dimensions 

21 field_name: Optional field name for context 

22 """ 

23 self.expected = expected 

24 self.actual = actual 

25 self.field_name = field_name 

26 

27 message = f"Vector dimension mismatch: expected {expected}, got {actual}" 

28 if field_name: 

29 message = f"{message} for field '{field_name}'" 

30 

31 super().__init__(message) 

32 

33 

34class VectorBackendError(VectorError): 

35 """Raised when vector backend operations fail.""" 

36 

37 pass 

38 

39 

40class VectorIndexError(VectorError): 

41 """Raised when vector index operations fail.""" 

42 

43 pass 

44 

45 

46class VectorNotSupportedError(VectorError): 

47 """Raised when vector operations are not supported by backend.""" 

48 

49 def __init__(self, backend: str, operation: str | None = None): 

50 """Initialize not supported error. 

51 

52 Args: 

53 backend: Name of the backend 

54 operation: Optional specific operation that's not supported 

55 """ 

56 self.backend = backend 

57 self.operation = operation 

58 

59 message = f"Vector operations not supported by {backend} backend" 

60 if operation: 

61 message = f"{message}: {operation}" 

62 

63 super().__init__(message) 

64 

65 

66class VectorValidationError(VectorError): 

67 """Raised when vector validation fails.""" 

68 

69 pass