File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -164,11 +164,24 @@ def _format_plain_output(self) -> str:
164164
165165 def _format_cyclonedx_output (self ) -> str :
166166 if not self .scanner .scan_results :
167- return None
168-
167+ return ''
169168 try :
169+ if 'results' not in self .scanner .scan_results or not self .scanner .scan_results ['results' ]:
170+ self .base .print_stderr ('ERROR: No scan results found' )
171+ return ''
172+
170173 first_result = self .scanner .scan_results ['results' ][0 ]
171- best_match_component = [c for c in first_result ['components' ] if c ['order' ] == 1 ][0 ]
174+
175+ best_match_components = [c for c in first_result .get ('components' , []) if c .get ('order' ) == 1 ]
176+ if not best_match_components :
177+ self .base .print_stderr ('ERROR: No best match component found' )
178+ return ''
179+
180+ best_match_component = best_match_components [0 ]
181+ if not best_match_component .get ('versions' ):
182+ self .base .print_stderr ('ERROR: No versions found for best match component' )
183+ return ''
184+
172185 best_match_version = best_match_component ['versions' ][0 ]
173186 purl = best_match_component ['purl' ]
174187
You can’t perform that action at this time.
0 commit comments