@@ -71,13 +71,20 @@ def _prepare_code_snippets(
7171
7272
7373class YAMLSyntaxError (PrettyDvcException , YAMLFileCorruptedError ):
74- def __init__ (self , path : str , yaml_text : str , exc : Exception ) -> None :
74+ def __init__ (
75+ self ,
76+ path : str ,
77+ yaml_text : str ,
78+ exc : Exception ,
79+ rev : Optional [str ] = None ,
80+ ) -> None :
7581 self .path : str = path
7682 self .yaml_text : str = yaml_text
7783 self .exc : Exception = exc
7884
7985 merge_conflicts = merge_conflict_marker .search (self .yaml_text )
8086 self .hint = " (possible merge conflicts)" if merge_conflicts else ""
87+ self .rev : Optional [str ] = rev
8188 super ().__init__ (self .path )
8289
8390 def __pretty_exc__ (self , ** kwargs : Any ) -> None :
@@ -133,7 +140,9 @@ def prepare_code(mark: "StreamMark") -> "Syntax":
133140 lines .insert (0 , "" )
134141
135142 rel = make_relpath (self .path )
136- lines .insert (0 , _prepare_message (f"'{ rel } ' is invalid{ self .hint } ." ))
143+ rev_msg = f" in revision '{ self .rev [:7 ]} '" if self .rev else ""
144+ msg_fmt = f"'{ rel } ' is invalid{ self .hint } { rev_msg } ."
145+ lines .insert (0 , _prepare_message (msg_fmt ))
137146 for line in lines :
138147 ui .error_write (line , styled = True )
139148
@@ -189,6 +198,7 @@ def __init__(
189198 exc : "MultipleInvalid" ,
190199 path : str = None ,
191200 text : str = None ,
201+ rev : str = None ,
192202 ) -> None :
193203 self .text = text or ""
194204 self .exc = exc
@@ -197,6 +207,7 @@ def __init__(
197207 self .path = path or ""
198208
199209 message = f"'{ rel } ' validation failed"
210+ message += " in revision '{}'" .format (rev [:7 ]) if rev else ""
200211 if len (self .exc .errors ) > 1 :
201212 message += f": { len (self .exc .errors )} errors"
202213 super ().__init__ (f"{ message } " )
@@ -254,13 +265,14 @@ def validate(
254265 schema : Callable [[_T ], _T ],
255266 text : str = None ,
256267 path : str = None ,
268+ rev : str = None ,
257269) -> _T :
258270 from voluptuous import MultipleInvalid
259271
260272 try :
261273 return schema (data )
262274 except MultipleInvalid as exc :
263- raise YAMLValidationError (exc , path , text ) from exc
275+ raise YAMLValidationError (exc , path , text , rev = rev ) from exc
264276
265277
266278def load (
@@ -271,6 +283,8 @@ def load(
271283 round_trip : bool = False ,
272284) -> Any :
273285 open_fn = fs .open if fs else open
286+ rev = getattr (fs , "rev" , None )
287+
274288 try :
275289 with open_fn (path , encoding = encoding ) as fd : # type: ignore
276290 text = fd .read ()
@@ -279,10 +293,10 @@ def load(
279293 raise EncodingError (path , encoding ) from exc
280294 except YAMLFileCorruptedError as exc :
281295 cause = exc .__cause__
282- raise YAMLSyntaxError (path , text , exc ) from cause
296+ raise YAMLSyntaxError (path , text , exc , rev = rev ) from cause
283297
284298 if schema :
285299 # not returning validated data, as it may remove
286300 # details from CommentedMap that we get from roundtrip parser
287- validate (data , schema , text = text , path = path )
301+ validate (data , schema , text = text , path = path , rev = rev )
288302 return data , text
0 commit comments