Skip to content

Commit 1677e61

Browse files
committed
Fix if there is no supported manifest files
1 parent 4db876e commit 1677e61

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.34"
9+
version = "2.2.35"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.34'
2+
__version__ = '2.2.35'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/__init__.py

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,42 @@ def create_full_scan_with_report_url(
525525
if save_manifest_tar_path and all_files and paths:
526526
self.save_manifest_tar(all_files, save_manifest_tar_path, paths[0])
527527

528+
# If no supported files found, create empty scan
528529
if not all_files:
529-
return diff
530-
531-
try:
532-
# Create new scan
533-
new_scan_start = time.time()
534-
new_full_scan = self.create_full_scan(all_files, params, base_paths=base_paths)
535-
new_scan_end = time.time()
536-
log.info(f"Total time to create new full scan: {new_scan_end - new_scan_start:.2f}")
537-
except APIFailure as e:
538-
log.error(f"Failed to create full scan: {e}")
539-
raise
530+
log.info("No supported manifest files found - creating empty scan")
531+
empty_files = Core.empty_head_scan_file()
532+
try:
533+
# Create new scan
534+
new_scan_start = time.time()
535+
new_full_scan = self.create_full_scan(empty_files, params, base_paths=base_paths)
536+
new_scan_end = time.time()
537+
log.info(f"Total time to create empty full scan: {new_scan_end - new_scan_start:.2f}")
538+
539+
# Clean up the temporary empty file
540+
for temp_file in empty_files:
541+
try:
542+
os.unlink(temp_file)
543+
log.debug(f"Cleaned up temporary file: {temp_file}")
544+
except OSError as e:
545+
log.warning(f"Failed to clean up temporary file {temp_file}: {e}")
546+
except Exception as e:
547+
# Clean up temp files even if scan creation fails
548+
for temp_file in empty_files:
549+
try:
550+
os.unlink(temp_file)
551+
except OSError:
552+
pass
553+
raise e
554+
else:
555+
try:
556+
# Create new scan
557+
new_scan_start = time.time()
558+
new_full_scan = self.create_full_scan(all_files, params, base_paths=base_paths)
559+
new_scan_end = time.time()
560+
log.info(f"Total time to create new full scan: {new_scan_end - new_scan_start:.2f}")
561+
except APIFailure as e:
562+
log.error(f"Failed to create full scan: {e}")
563+
raise
540564

541565
# Construct report URL
542566
base_socket = "https://socket.dev/dashboard/org"
@@ -889,8 +913,11 @@ def create_new_diff(
889913
if save_manifest_tar_path and all_files and paths:
890914
self.save_manifest_tar(all_files, save_manifest_tar_path, paths[0])
891915

916+
# If no supported files found, create empty scan for comparison
917+
scan_files = all_files
892918
if not all_files:
893-
return Diff(id="NO_DIFF_RAN", diff_url="", report_url="")
919+
log.info("No supported manifest files found - creating empty scan for diff comparison")
920+
scan_files = Core.empty_head_scan_file()
894921

895922
try:
896923
# Get head scan ID
@@ -933,19 +960,43 @@ def create_new_diff(
933960
raise e
934961

935962
# Create new scan
963+
temp_files_to_cleanup = []
964+
if not all_files: # We're using empty scan files
965+
temp_files_to_cleanup = scan_files
966+
936967
try:
937968
new_scan_start = time.time()
938-
new_full_scan = self.create_full_scan(all_files, params, base_paths=base_paths)
969+
new_full_scan = self.create_full_scan(scan_files, params, base_paths=base_paths)
939970
new_scan_end = time.time()
940971
log.info(f"Total time to create new full scan: {new_scan_end - new_scan_start:.2f}")
941972
except APIFailure as e:
942973
log.error(f"API Error: {e}")
974+
# Clean up temp files if any
975+
for temp_file in temp_files_to_cleanup:
976+
try:
977+
os.unlink(temp_file)
978+
except OSError:
979+
pass
943980
sys.exit(1)
944981
except Exception as e:
945982
import traceback
946983
log.error(f"Error creating new full scan: {str(e)}")
947984
log.error(f"Stack trace:\n{traceback.format_exc()}")
985+
# Clean up temp files if any
986+
for temp_file in temp_files_to_cleanup:
987+
try:
988+
os.unlink(temp_file)
989+
except OSError:
990+
pass
948991
raise
992+
finally:
993+
# Clean up temporary empty files if they were created
994+
for temp_file in temp_files_to_cleanup:
995+
try:
996+
os.unlink(temp_file)
997+
log.debug(f"Cleaned up temporary file: {temp_file}")
998+
except OSError as e:
999+
log.warning(f"Failed to clean up temporary file {temp_file}: {e}")
9491000

9501001
# Handle diff generation - now we always have both scans
9511002
scans_ready = self.check_full_scans_status(head_full_scan_id, new_full_scan.id)

0 commit comments

Comments
 (0)