gogo2/crypto/gogo2/fix_try_blocks.py
2025-03-12 00:56:32 +02:00

22 lines
732 B
Python

import re
def fix_try_blocks():
with open('main.py', 'r') as f:
content = f.read()
# Find all try blocks without except or finally
pattern = r'(\s+)try:\s*\n((?:\1\s+.*\n)+?)(?!\1\s*except|\1\s*finally)'
# Replace with try-except blocks
fixed_content = re.sub(pattern,
r'\1try:\n\2\1except Exception as e:\n\1 logger.error(f"Error: {e}")\n\1 logger.error(f"Traceback: {traceback.format_exc()}")\n\1 return None\n\n',
content)
# Write the fixed content back to the file
with open('main.py', 'w') as f:
f.write(fixed_content)
print("Try blocks fixed!")
if __name__ == "__main__":
fix_try_blocks()