refactor: Remove try/except blocks in main

This commit is contained in:
Tanner Collin (aider) 2025-05-22 16:59:08 -06:00
parent fb1389401b
commit 52e6851594

View File

@ -6,37 +6,22 @@ def main():
found in the archive. found in the archive.
""" """
har_file_path = "data.har" har_file_path = "data.har"
try: with open(har_file_path, 'r', encoding='utf-8') as f:
with open(har_file_path, 'r', encoding='utf-8') as f: har_data = json.load(f)
har_data = json.load(f)
except FileNotFoundError: entries = har_data.get('log', {}).get('entries', [])
print(f"Error: The file '{har_file_path}' was not found.") if not entries:
return print("No entries found in the HAR file.")
except json.JSONDecodeError:
print(f"Error: Could not decode JSON from the file '{har_file_path}'.")
return
except Exception as e:
print(f"An unexpected error occurred while reading the file: {e}")
return return
try: print("Files found in the HAR archive:")
entries = har_data.get('log', {}).get('entries', []) for entry in entries:
if not entries: request = entry.get('request', {})
print("No entries found in the HAR file.") url = request.get('url')
return if url:
print(url)
print("Files found in the HAR archive:") else:
for entry in entries: print("Entry found with no request URL.")
request = entry.get('request', {})
url = request.get('url')
if url:
print(url)
else:
print("Entry found with no request URL.")
except AttributeError:
print("Error: The HAR file does not have the expected structure ('log' or 'entries' missing).")
except Exception as e:
print(f"An unexpected error occurred while processing HAR entries: {e}")
if __name__ == "__main__": if __name__ == "__main__":