22import os
33import re
44from collections .abc import Hashable
5- from typing import Any , List , Mapping , Union
5+ from typing import Any , List , Mapping , Optional , Union
66
77import yaml
88from yaml .constructor import ConstructorError
@@ -25,6 +25,7 @@ def construct_yaml_map(self, node: yaml.MappingNode) -> Any:
2525 path = mapping .pop (CONSTRUCTOR_KEY )
2626 object_path_elements = path .split ("." )
2727 remaining_path_elements : List [str ] = []
28+ exceptions : list [Optional [str ]] = []
2829 while object_path_elements :
2930 try :
3031 cls = self .find_python_name (
@@ -33,10 +34,13 @@ def construct_yaml_map(self, node: yaml.MappingNode) -> Any:
3334 unsafe = True ,
3435 )
3536 break
36- except ConstructorError :
37+ except ConstructorError as error :
38+ exceptions .append (error .problem )
3739 remaining_path_elements .insert (0 , object_path_elements .pop (- 1 ))
3840 else :
39- raise NotFoundError (f"Could not load element { path } { node .start_mark } " )
41+ raise NotFoundError (
42+ f"Could not load element { path } { node .start_mark } , exceptions encountered: { exceptions !r} "
43+ ) from None
4044 for path_element in remaining_path_elements :
4145 cls = getattr (cls , path_element )
4246
0 commit comments