Coverage for sources/appcore/exceptions.py: 100%
25 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-26 19:13 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-26 19:13 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
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#============================================================================#
21''' Family of exceptions for package API.
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.
27 Exception Hierarchy
28 ===================
30 The exception hierarchy follows a two-tier design:
32 * :class:`Omniexception` - Base for all package exceptions
33 * :class:`Omnierror` - Base for error exceptions, inherits from both
34 ``Omniexception`` and ``Exception``
36 Usage
37 =====
39 Catch all package errors with :class:`Omnierror` or with built-in exception
40 types. See class inheritance for details.
41'''
44from . import __
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. '''
56class Omnierror( Omniexception, Exception ):
57 ''' Base for error exceptions raised by package API. '''
60class AddressLocateFailure( Omnierror, LookupError ):
61 ''' Failure to locate address. '''
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}." )
71class AsyncAssertionFailure( Omnierror, AssertionError, TypeError ):
72 ''' Assertion of awaitability of entity failed. '''
74 def __init__( self, entity: __.typx.Any ):
75 super( ).__init__( f"Entity must be awaitable: {entity!r}" )
78class ContextInvalidity( Omnierror, TypeError, ValueError ):
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}" )
86class DependencyAbsence( Omnierror, ImportError ):
88 def __init__( self, dependency: str, feature: str ):
89 super( ).__init__(
90 f"Optional dependency {dependency!r} missing "
91 f"feature {feature!r}." )
94class EntryAssertionFailure( Omnierror, AssertionError, KeyError ):
95 ''' Assertion of entry in dictionary failed. '''
97 def __init__( self, subject: str, name: str ):
98 super( ).__init__( f"Could not find entry '{name}' in {subject}." )
101class FileLocateFailure( Omnierror, FileNotFoundError ):
102 ''' Failure to locate file. '''
104 def __init__( self, subject: str, name: str ):
105 super( ).__init__(
106 f"Could not locate file '{name}' for {subject}." )
109class OperationInvalidity( Omnierror, RuntimeError ):
110 ''' Invalid operation. '''
112 def __init__( self, subject: str, name: str ):
113 super( ).__init__(
114 f"Could not perform operation '{name}' on {subject}." )