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

32 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-26 15:45 -0700

1"""Vector-specific exceptions. 

2 

3This module defines exception types for vector operations, 

4built on the common exception framework from dataknobs_common. 

5""" 

6 

7from __future__ import annotations 

8 

9from dataknobs_common import ( 

10 DataknobsError, 

11 OperationError, 

12 ResourceError, 

13 ValidationError, 

14) 

15 

16# Create VectorError as alias to DataknobsError for backward compatibility 

17VectorError = DataknobsError 

18 

19 

20class VectorDimensionError(ValidationError): 

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

22 

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

24 """Initialize dimension error. 

25 

26 Args: 

27 expected: Expected number of dimensions 

28 actual: Actual number of dimensions 

29 field_name: Optional field name for context 

30 """ 

31 self.expected = expected 

32 self.actual = actual 

33 self.field_name = field_name 

34 

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

36 if field_name: 

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

38 

39 context = {"expected": expected, "actual": actual} 

40 if field_name: 

41 context["field_name"] = field_name 

42 

43 super().__init__(message, context=context) 

44 

45 

46class VectorBackendError(ResourceError): 

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

48 

49 pass 

50 

51 

52class VectorIndexError(OperationError): 

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

54 

55 pass 

56 

57 

58class VectorNotSupportedError(OperationError): 

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

60 

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

62 """Initialize not supported error. 

63 

64 Args: 

65 backend: Name of the backend 

66 operation: Optional specific operation that's not supported 

67 """ 

68 self.backend = backend 

69 self.operation = operation 

70 

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

72 if operation: 

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

74 

75 context = {"backend": backend} 

76 if operation: 

77 context["operation"] = operation 

78 

79 super().__init__(message, context=context) 

80 

81 

82class VectorValidationError(ValidationError): 

83 """Raised when vector validation fails.""" 

84 

85 pass