Coverage for sources/appcore/exceptions.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-09-27 22:40 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Family of exceptions for package API. 

22 

23 This module defines a comprehensive exception hierarchy for the appcore 

24 library, providing specific exception types for different failure modes 

25 while maintaining a consistent interface for error handling and debugging. 

26 

27 Exception Hierarchy 

28 =================== 

29 

30 The exception hierarchy follows a two-tier design: 

31 

32 * :class:`Omniexception` - Base for all package exceptions 

33 * :class:`Omnierror` - Base for error exceptions, inherits from both 

34 ``Omniexception`` and ``Exception`` 

35 

36 Usage 

37 ===== 

38 

39 Catch all package errors with :class:`Omnierror` or with built-in exception 

40 types. See class inheritance for details. 

41''' 

42 

43 

44from . import __ 

45 

46 

47class Omniexception( 

48 __.immut.Object, BaseException, 

49 instances_mutables = ( '__cause__', '__context__' ), 

50 instances_visibles = ( 

51 '__cause__', '__context__', __.immut.is_public_identifier ), 

52): 

53 ''' Base for all exceptions raised by package API. ''' 

54 

55 

56class Omnierror( Omniexception, Exception ): 

57 ''' Base for error exceptions raised by package API. ''' 

58 

59 

60class AddressLocateFailure( Omnierror, LookupError ): 

61 ''' Failure to locate address. ''' 

62 

63 def __init__( 

64 self, subject: str, address: __.cabc.Sequence[ str ], part: str 

65 ): 

66 super( ).__init__( 

67 f"Could not locate part '{part}' of address '{address}' " 

68 f"in {subject}." ) 

69 

70 

71class AsyncAssertionFailure( Omnierror, AssertionError, TypeError ): 

72 ''' Assertion of awaitability of entity failed. ''' 

73 

74 def __init__( self, entity: __.typx.Any ): 

75 super( ).__init__( f"Entity must be awaitable: {entity!r}" ) 

76 

77 

78class ContextInvalidity( Omnierror, TypeError, ValueError ): 

79 

80 def __init__( self, auxdata: __.typx.Any ): 

81 # TODO: Add module name to fully-qualified name. 

82 fqname = type( auxdata ).__qualname__ 

83 super( ).__init__( f"Invalid context object type: {fqname}" ) 

84 

85 

86class DependencyAbsence( Omnierror, ImportError ): 

87 

88 def __init__( self, dependency: str, feature: str ): 

89 super( ).__init__( 

90 f"Optional dependency {dependency!r} missing " 

91 f"feature {feature!r}." ) 

92 

93 

94class EntryAssertionFailure( Omnierror, AssertionError, KeyError ): 

95 ''' Assertion of entry in dictionary failed. ''' 

96 

97 def __init__( self, subject: str, name: str ): 

98 super( ).__init__( f"Could not find entry '{name}' in {subject}." ) 

99 

100 

101class FileLocateFailure( Omnierror, FileNotFoundError ): 

102 ''' Failure to locate file. ''' 

103 

104 def __init__( self, subject: str, name: str ): 

105 super( ).__init__( 

106 f"Could not locate file '{name}' for {subject}." ) 

107 

108 

109class OperationInvalidity( Omnierror, RuntimeError ): 

110 ''' Invalid operation. ''' 

111 

112 def __init__( self, subject: str, name: str ): 

113 super( ).__init__( 

114 f"Could not perform operation '{name}' on {subject}." )