11from lark .exceptions import UnexpectedToken
22
3- class ValidationError (Exception ):
4- pass
3+ class _ValidationError (Exception ):
4+ def __init__ (self , * args , ** kwargs ):
5+ if self .__class__ is _ValidationError :
6+ raise TypeError ("Do not raise _ValidationError directly." )
7+ super ().__init__ (* args , ** kwargs )
58
69class ErrorCollector :
710 def __init__ (self ):
@@ -14,7 +17,7 @@ def raise_if_any(self):
1417 if self .errors :
1518 raise CollectedValidationErrors (self .errors )
1619
17- class CollectedValidationErrors (ValidationError ):
20+ class CollectedValidationErrors (_ValidationError ):
1821 def __init__ (self , errors ):
1922 self .errors = errors
2023
@@ -24,7 +27,7 @@ def asdict(self, with_message=True):
2427 def __str__ (self ):
2528 return f"{ len (self .errors )} validation error(s) collected:\n " + "\n \n " .join (str (e ) for e in self .errors )
2629
27- class SyntaxError (ValidationError ):
30+ class SyntaxError (_ValidationError ):
2831 def __init__ (self , filecontent , exception ):
2932 self .filecontent = filecontent
3033 self .exception = exception
@@ -57,7 +60,7 @@ def __str__(self):
5760 return f"On line { d ['lineno' ]} column { d ['column' ]} :\n Unexpected { sth } { d ['found_type' ]} ('{ d ['found_value' ]} ')\n Expecting { exp } \n { d ['lineno' ]:05d} | { d ['line' ]} \n { ' ' * (self .exception .column - 1 )} ^"
5861
5962
60- class DuplicateNameError (ValidationError ):
63+ class DuplicateNameError (_ValidationError ):
6164 def __init__ (self , filecontent , name , linenumbers ):
6265 self .name = name
6366 self .filecontent = filecontent
@@ -83,7 +86,7 @@ def build():
8386 return "\n " .join (build ())
8487
8588
86- class HeaderFieldError (ValidationError ):
89+ class HeaderFieldError (_ValidationError ):
8790 def __init__ (self , field , found_len , expected_len ):
8891 self .field = field
8992 self .found_len = found_len
0 commit comments