@@ -580,6 +580,11 @@ def extract_generic_build_command_info(
580580 list[GenericBuildCommandInfo]
581581 The list of GenericBuildCommandInfo instances that store build command information
582582 representing by the Build Check Facts.
583+
584+ Raises
585+ ------
586+ json.decoder.JSONDecodeError
587+ If we failed to decode the JSON-serialized values stored in the Build*Facts instances.
583588 """
584589 result = []
585590 for fact in check_facts :
@@ -615,27 +620,73 @@ def extract_generic_build_command_info(
615620 return result
616621
617622
618- def lookup_any_build_command (component_id : int , session : Session ) -> Sequence [GenericBuildCommandInfo ]:
619- """WIP."""
623+ def lookup_any_build_command (component_id : int , session : Session ) -> list [GenericBuildCommandInfo ]:
624+ """Return a list of ``GenericBuildCommandInfo`` instances from looking up any available build command.
625+
626+ We will look for available build command from build-related check facts.
627+
628+ Parameters
629+ ----------
630+ component_id: int
631+ The component id to lookup the build command.
632+ session: Session
633+ The SQLAlchemy session to the database for the lookup.
634+
635+ Returns
636+ -------
637+ list[GenericBuildCommandInfo]
638+ This list will be empty if there is no available build command for this component.
639+
640+ Raises
641+ ------
642+ QueryMacaronDatabaseError
643+ If there is an unexpected error when executing the SQLAlchemy query for looking up the build commands.
644+ Raised by "lookup_*_check" functions
645+ """
620646 build_as_code_check_facts = lookup_build_as_code_check (
621647 component_id = component_id ,
622648 session = session ,
623649 )
624650 if build_as_code_check_facts :
625- return extract_generic_build_command_info (build_as_code_check_facts )
651+ try :
652+ return extract_generic_build_command_info (build_as_code_check_facts )
653+ except json .decoder .JSONDecodeError as error :
654+ logger .debug (
655+ "Failed to extract generic build command info for build as code check facts for component id %s. "
656+ + "Error %s. Continue" ,
657+ component_id ,
658+ error ,
659+ )
626660
627661 build_service_check_facts = lookup_build_service_check (
628662 component_id = component_id ,
629663 session = session ,
630664 )
631665 if build_service_check_facts :
632- return extract_generic_build_command_info (build_service_check_facts )
666+ try :
667+ return extract_generic_build_command_info (build_service_check_facts )
668+ except json .decoder .JSONDecodeError as error :
669+ logger .debug (
670+ "Failed to extract generic build command info for build servoce check facts for component id %s. "
671+ + "Error %s. Continue" ,
672+ component_id ,
673+ error ,
674+ )
633675
634676 build_script_check_facts = lookup_build_script_check (
635677 component_id = component_id ,
636678 session = session ,
637679 )
638- return extract_generic_build_command_info (build_script_check_facts )
680+ try :
681+ return extract_generic_build_command_info (build_script_check_facts )
682+ except json .decoder .JSONDecodeError as error :
683+ logger .debug (
684+ "Failed to extract generic build command info for build as code check facts for component id %s. "
685+ + "Error %s. Continue" ,
686+ component_id ,
687+ error ,
688+ )
689+ return []
639690
640691
641692def lookup_repository (component_id : int , session : Session ) -> Repository | None :
0 commit comments