Coverage for sources / vibelinter / exceptions.py: 62%
32 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-01 02:35 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-01 02:35 +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. '''
24from . import __
27class Omniexception( __.immut.exceptions.Omniexception ):
28 ''' Base for all exceptions raised by package API. '''
31class Omnierror( Omniexception, Exception ):
32 ''' Base for error exceptions raised by package API. '''
34 def render_as_json( self ) -> dict[ str, __.typx.Any ]:
35 ''' Renders exception as JSON-compatible dictionary. '''
36 return {
37 'type': self.__class__.__name__,
38 'message': str( self ),
39 }
41 def render_as_text( self ) -> tuple[ str, ... ]:
42 ''' Renders exception as text lines. '''
43 return (
44 f'## {self.__class__.__name__}',
45 f'**Message**: {self}',
46 )
49# Rule execution exceptions
50class RuleExecuteFailure( Omnierror ):
51 ''' Raised when rule execution encounters unrecoverable error. '''
53 def __init__( self, context: str ) -> None:
54 super( ).__init__(
55 f'Rule execution failed for {context!r}' )
56 self.context = context
58 def render_as_json( self ) -> dict[ str, __.typx.Any ]:
59 ''' Renders exception with context information. '''
60 return {
61 'type': self.__class__.__name__,
62 'message': str( self ),
63 'context': self.context,
64 }
66 def render_as_text( self ) -> tuple[ str, ... ]:
67 ''' Renders exception with context information. '''
68 return (
69 f'## {self.__class__.__name__}',
70 f'**Message**: {self}',
71 f'**Context**: {self.context}',
72 )
75class MetadataProvideFailure( Omnierror ):
76 ''' Raised when LibCST metadata provider initialization fails. '''
78 def __init__( self, filename: str ) -> None:
79 super( ).__init__(
80 f'Failed to initialize LibCST metadata for {filename!r}' )
81 self.filename = filename
83 def render_as_json( self ) -> dict[ str, __.typx.Any ]:
84 ''' Renders exception with filename information. '''
85 return {
86 'type': self.__class__.__name__,
87 'message': str( self ),
88 'filename': self.filename,
89 }
91 def render_as_text( self ) -> tuple[ str, ... ]:
92 ''' Renders exception with filename information. '''
93 return (
94 f'## {self.__class__.__name__}',
95 f'**Message**: {self}',
96 f'**Filename**: {self.filename}',
97 )
100# Configuration exceptions
101class RuleRegistryInvalidity( Omnierror ):
102 ''' Raised when rule registry contains invalid mappings. '''
104 def __init__( self, identifier: str ) -> None:
105 super( ).__init__(
106 f'Unknown or invalid rule identifier: {identifier!r}' )
107 self.identifier = identifier
109 def render_as_json( self ) -> dict[ str, __.typx.Any ]:
110 ''' Renders exception with identifier information. '''
111 return {
112 'type': self.__class__.__name__,
113 'message': str( self ),
114 'identifier': self.identifier,
115 }
117 def render_as_text( self ) -> tuple[ str, ... ]:
118 ''' Renders exception with identifier information. '''
119 return (
120 f'## {self.__class__.__name__}',
121 f'**Message**: {self}',
122 f'**Identifier**: {self.identifier}',
123 )
126class RuleConfigureFailure( Omnierror ):
127 ''' Raised when rule configuration parameters are invalid. '''