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

1"""Exception hierarchy for indium.

2

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

4 for compatibility with standard validation flows.

5"""

6

7 from typing import Optional

8

9

10 class IndiumError(ValueError):

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

12

13 pass

14

15

16 class 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

34 class 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