@@ -20,6 +20,7 @@ def parsing_yml(yaml_file, base_path, print_log=True):
2020 oss_list = []
2121 license_list = []
2222 idx = 1
23+ err_reason = ""
2324 OLD_YAML_ROOT_ELEMENT = ['Open Source Software Package' ,
2425 'Open Source Package' ]
2526
@@ -32,6 +33,13 @@ def parsing_yml(yaml_file, base_path, print_log=True):
3233 else :
3334 relative_path = ""
3435 doc = yaml .safe_load (codecs .open (yaml_file , "r" , "utf-8" ))
36+ # If yaml file is empty, return immediately
37+ if doc is None :
38+ err_reason = "empty"
39+ if print_log :
40+ _logger .warning (f"The yaml file is empty file: { yaml_file } " )
41+ return oss_list , license_list , err_reason
42+
3543 is_old_format = any (x in doc for x in OLD_YAML_ROOT_ELEMENT )
3644
3745 for root_element in doc :
@@ -46,19 +54,21 @@ def parsing_yml(yaml_file, base_path, print_log=True):
4654 for key , value in oss .items ():
4755 if key :
4856 key = key .lower ().strip ()
49- set_value_switch (item , key , value )
57+ set_value_switch (item , key , value , yaml_file )
5058 oss_list .append (item )
5159 license_list .extend (item .license )
5260 idx += 1
5361 except AttributeError as ex :
5462 if print_log :
55- _logger .error (f"Not supported yaml file format { ex } " )
63+ _logger .warning (f"Not supported yaml file format: { yaml_file } { ex } " )
5664 oss_list = []
65+ err_reason = "not_supported"
5766 except yaml .YAMLError :
5867 if print_log :
59- _logger .warning (f"Can't parse yaml - skip to parse yaml file: { yaml_file } " )
68+ _logger .warning (f"Error to parse yaml - skip to parse yaml file: { yaml_file } " )
6069 oss_list = []
61- return oss_list , set (license_list )
70+ err_reason = "yaml_error"
71+ return oss_list , set (license_list ), err_reason
6272
6373
6474def find_sbom_yaml_files (path_to_find ):
@@ -82,7 +92,7 @@ def find_sbom_yaml_files(path_to_find):
8292 return oss_pkg_files
8393
8494
85- def set_value_switch (oss , key , value ):
95+ def set_value_switch (oss , key , value , yaml_file ):
8696 if key in ['oss name' , 'name' ]:
8797 oss .name = value
8898 elif key in ['oss version' , 'version' ]:
@@ -105,3 +115,5 @@ def set_value_switch(oss, key, value):
105115 oss .yocto_package = value
106116 elif key == 'yocto_recipe' :
107117 oss .yocto_recipe = value
118+ else :
119+ _logger .debug (f"file:{ yaml_file } - key:{ key } cannot be parsed" )
0 commit comments