Skip to content

Commit 44584b6

Browse files
committed
[SP-2587] feat: improvements
1 parent 450ac5e commit 44584b6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/scanoss/scanners/scanner_hfh.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)