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

18 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-19 22:17 +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 

24from . import __ 

25 

26 

27class Omniexception( 

28 __.immut.Object, BaseException, 

29 instances_mutables = ( '__cause__', ), # for PyPy 

30 instances_visibles = ( 

31 '__cause__', '__context__', 

32 __.immut.is_public_identifier ), 

33): 

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

35 

36 

37class Omnierror( Omniexception, Exception ): 

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

39 

40 

41class AddressLocateFailure( Omnierror, LookupError ): 

42 ''' Failure to locate address. ''' 

43 

44 def __init__( 

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

46 ): 

47 super( ).__init__( 

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

49 f"in {subject}." ) 

50 

51 

52class AsyncAssertionFailure( Omnierror, AssertionError, TypeError ): 

53 ''' Assertion of awaitability of entity failed. ''' 

54 

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

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

57 

58 

59class EntryAssertionFailure( Omnierror, AssertionError, KeyError ): 

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

61 

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

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

64 

65 

66class FileLocateFailure( Omnierror, FileNotFoundError ): 

67 ''' Failure to locate file. ''' 

68 

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

70 super( ).__init__( 

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

72 

73 

74class OperationInvalidity( Omnierror, RuntimeError ): 

75 ''' Invalid operation. ''' 

76 

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

78 super( ).__init__( 

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