File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -238,7 +238,9 @@ class DataProcessorFactory:
238238 def get_processor (cls , strategy : ObjectStrategy ) -> DataProcessor :
239239 processor_class = cls ._processors .get (strategy )
240240 if not processor_class :
241- raise ValueError (f"Unknown strategy: { strategy } " )
241+ raise ValueError (
242+ f"Unknown strategy: { strategy } - no processor found. Valid strategies are: { list (cls ._processors .keys ())} "
243+ )
242244 return processor_class ()
243245
244246 @classmethod
@@ -699,14 +701,20 @@ class ObjectFile(InfrahubFile):
699701 @property
700702 def spec (self ) -> InfrahubObjectFileData :
701703 if not self ._spec :
702- self ._spec = InfrahubObjectFileData (** self .data .spec )
704+ try :
705+ self ._spec = InfrahubObjectFileData (** self .data .spec )
706+ except Exception as exc :
707+ raise ValidationError (identifier = str (self .location ), message = str (exc ))
703708 return self ._spec
704709
705710 def validate_content (self ) -> None :
706711 super ().validate_content ()
707712 if self .kind != InfrahubFileKind .OBJECT :
708713 raise ValueError ("File is not an Infrahub Object file" )
709- self ._spec = InfrahubObjectFileData (** self .data .spec )
714+ try :
715+ self ._spec = InfrahubObjectFileData (** self .data .spec )
716+ except Exception as exc :
717+ raise ValidationError (identifier = str (self .location ), message = str (exc ))
710718
711719 async def validate_format (self , client : InfrahubClient , branch : str | None = None ) -> None :
712720 self .validate_content ()
Original file line number Diff line number Diff line change @@ -228,3 +228,21 @@ async def test_get_relationship_info_tags(
228228 rel_info = await get_relationship_info (client , location_schema , "tags" , data )
229229 assert rel_info .is_valid == is_valid
230230 assert rel_info .format == format
231+
232+
233+ async def test_invalid_object_expansion_strategy (
234+ client : InfrahubClient , mock_schema_query_01 : HTTPXMock , location_expansion
235+ ) -> None :
236+ obj = ObjectFile (location = "some/path" , content = location_expansion )
237+
238+ from infrahub_sdk .spec .object import DataProcessorFactory , ObjectStrategy # noqa: PLC0415
239+
240+ # Patch _processors to remove the invalid strategy
241+ original_processors = DataProcessorFactory ._processors .copy ()
242+ try :
243+ DataProcessorFactory ._processors [ObjectStrategy .RANGE_EXPAND ] = None
244+ with pytest .raises (ValueError ) as exc :
245+ await obj .validate_format (client = client )
246+ assert "Unknown strategy" in str (exc .value )
247+ finally :
248+ DataProcessorFactory ._processors = original_processors
You can’t perform that action at this time.
0 commit comments