Coverage for sources/mimeogram/exceptions.py: 100%
43 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-17 00:11 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-17 00:11 +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 * ``Omniexception``: Base for all package exceptions
24 * ``Omnierror``: Base for all package errors
25'''
28from . import __
31class Omniexception( BaseException, metaclass = __.ImmutableClass ):
32 ''' Base for all exceptions raised by package API. '''
33 # TODO: Class attribute concealment.
34 # TODO: Instance attribute concealment and immutability.
36 _attribute_visibility_includes_: __.cabc.Collection[ str ] = (
37 frozenset( ( '__cause__', '__context__', ) ) )
40class Omnierror( Omniexception, Exception ):
41 ''' Base for error exceptions raised by package API. '''
44class ContentAcquireFailure( Omnierror ):
45 ''' Failure to acquire content from location. '''
47 def __init__( self, location: str | __.Path ):
48 super( ).__init__( f"Could not acquire content from '{location}'." )
51class ContentDecodeFailure( Omnierror ):
52 ''' Failure to decode content as character set from location. '''
54 def __init__( self, location: str | __.Path, charset: str ):
55 super( ).__init__(
56 f"Could not decode content at '{location}' "
57 f"as character set '{charset}'." )
60class ContentUpdateFailure( Omnierror ):
61 ''' Failure to update content at location. '''
63 def __init__( self, location: str | __.Path ):
64 super( ).__init__( f"Could not update content at '{location}'." )
67class DifferencesProcessFailure( Omnierror ):
68 ''' Failure during diff processing. '''
70 def __init__( self, reason: str ):
71 super( ).__init__( f"Could not process changes. Reason: {reason}" )
74class EditorFailure( Omnierror ):
75 ''' Failure while operating editor. '''
77 def __init__( self, cause: str | Exception ):
78 super( ).__init__( f"Could not edit content. Cause: {cause}" )
81class LocationInvalidity( Omnierror ):
82 ''' Invalid location. '''
84 def __init__( self, location: str | __.Path ):
85 super( ).__init__( f"Invalid location '{location}'." )
88class MimeogramFormatEmpty( Omnierror ):
89 ''' Attempt to format empty mimeogram. '''
91 def __init__( self ):
92 super( ).__init__( "Cannot format empty mimeogram." )
95class MimeogramParseFailure( Omnierror ):
96 ''' Failure to parse mimeogram content. '''
98 def __init__( self, reason: str ):
99 super( ).__init__( f"Could not parse mimeogram. Reason: {reason}" )
102class PagerFailure( Omnierror ):
103 ''' Failure while operating pager. '''
105 def __init__( self, cause: str | Exception ):
106 super( ).__init__( f"Could not display content. Cause: {cause}" )
109class ProgramAbsenceError( Omnierror ):
110 ''' Could not discover valid editor. '''
112 def __init__( self, species: str ):
113 super( ).__init__( f"Could not discover valid {species}." )
116class TextualMimetypeInvalidity( Omnierror ):
117 ''' Invalid textual MIME type for content at location. '''
119 def __init__( self, location: str | __.Path, mimetype: str ):
120 super( ).__init__(
121 f"Invalid MIME type '{mimetype}' for content at '{location}'." )
124class UrlSchemeNoSupport( Omnierror ):
125 ''' Unsupported URL scheme. '''
127 def __init__( self, url: str ):
128 super( ).__init__( f"Scheme of URL '{url}' is not supported." )
131class UserOperateCancellation( Omniexception ):
132 ''' Operation cancelled by user. '''
134 def __init__( self, cause: BaseException ):
135 super( ).__init__( f"Operation cancelled by user. Cause: {cause}" )