Coverage for src/indium/_exceptions.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-01-08 22:34 +0000

1"""Exception hierarchy for indium. 

2 

3Following elemental-* family pattern: all exceptions inherit from ValueError 

4for compatibility with standard validation flows. 

5""" 

6 

7from typing import Optional 

8 

9 

10class IndiumError(ValueError): 

11 """Base exception for all indium errors.""" 

12 

13 pass 

14 

15 

16class InvalidTextError(IndiumError): 

17 """Raised when text contains invalid or malformed Unicode. 

18 

19 Attributes: 

20 position: Optional position where the invalid character was found 

21 """ 

22 

23 def __init__(self, message: str, position: Optional[int] = None) -> None: 

24 """Initialize InvalidTextError. 

25 

26 Args: 

27 message: Error description 

28 position: Position of invalid character (if known) 

29 """ 

30 super().__init__(message) 

31 self.position = position 

32 

33 

34class TruncationError(IndiumError): 

35 """Raised when text cannot be safely truncated at requested position. 

36 

37 This may occur when the truncation point falls within a grapheme cluster 

38 that cannot be split. 

39 """ 

40 

41 pass