diff --git a/apps/blockchain-node/src/aitbc_chain/p2p_network.py b/apps/blockchain-node/src/aitbc_chain/p2p_network.py index 047cec95..c019a590 100644 --- a/apps/blockchain-node/src/aitbc_chain/p2p_network.py +++ b/apps/blockchain-node/src/aitbc_chain/p2p_network.py @@ -557,7 +557,7 @@ class P2PNetworkService: writer.close() try: await writer.wait_closed() - except: + except Exception: pass def _get_gpu_count(self) -> int: diff --git a/apps/blockchain-node/src/aitbc_chain/rpc/router.py b/apps/blockchain-node/src/aitbc_chain/rpc/router.py index 6ee7496b..ddc2fb86 100755 --- a/apps/blockchain-node/src/aitbc_chain/rpc/router.py +++ b/apps/blockchain-node/src/aitbc_chain/rpc/router.py @@ -113,7 +113,7 @@ def _normalize_transaction_data(tx_data: Dict[str, Any], chain_id: str) -> Dict[ try: import json payload = json.loads(payload) - except: + except Exception: payload = {} if not isinstance(payload, dict): diff --git a/apps/coordinator-api/scripts/migrate_complete.py b/apps/coordinator-api/scripts/migrate_complete.py index 782f7777..9ec04843 100755 --- a/apps/coordinator-api/scripts/migrate_complete.py +++ b/apps/coordinator-api/scripts/migrate_complete.py @@ -81,12 +81,12 @@ def migrate_all_data(): for i, value in enumerate(row): col_name = column_names[i] # Handle special cases - if col_name in ['payload', 'constraints', 'result', 'receipt', 'capabilities', + if col_name in ['payload', 'constraints', 'result', 'receipt', 'capabilities', 'extra_metadata', 'sla', 'attributes', 'metadata'] and value: if isinstance(value, str): try: value = json.loads(value) - except: + except Exception: pass elif col_name in ['balance', 'price', 'average_job_duration_ms'] and value is not None: value = Decimal(str(value)) diff --git a/apps/coordinator-api/scripts/migrate_to_postgresql.py b/apps/coordinator-api/scripts/migrate_to_postgresql.py index 8323f384..8760ecee 100755 --- a/apps/coordinator-api/scripts/migrate_to_postgresql.py +++ b/apps/coordinator-api/scripts/migrate_to_postgresql.py @@ -276,7 +276,7 @@ def migrate_data(): if isinstance(value, str): try: value = json.loads(value) - except: + except Exception: pass elif key in ['balance', 'price', 'average_job_duration_ms']: # Handle numeric fields diff --git a/apps/coordinator-api/src/app/routers/agent_integration_router.py b/apps/coordinator-api/src/app/routers/agent_integration_router.py index 9106df10..a907c756 100755 --- a/apps/coordinator-api/src/app/routers/agent_integration_router.py +++ b/apps/coordinator-api/src/app/routers/agent_integration_router.py @@ -454,7 +454,7 @@ async def get_production_dashboard( try: monitoring_manager = AgentMonitoringManager(session) metrics = await monitoring_manager.get_deployment_metrics(config.id) - except: + except Exception: metrics = {"aggregated_metrics": {}} dashboard_data["deployments"].append( diff --git a/scripts/fix_bare_except.py b/scripts/fix_bare_except.py new file mode 100644 index 00000000..5fcd928b --- /dev/null +++ b/scripts/fix_bare_except.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +"""Fix bare except clauses by replacing 'except:' with 'except Exception:'""" + +import ast +import sys +from pathlib import Path + + +def fix_bare_except(file_path): + """Fix bare except clauses in a Python file""" + try: + with open(file_path, 'r') as f: + content = f.read() + + # Parse the file to check for syntax errors + try: + ast.parse(content) + except SyntaxError: + print(f"Skipping {file_path}: syntax error") + return False + + # Split into lines + lines = content.split('\n') + modified = False + new_lines = [] + + i = 0 + while i < len(lines): + line = lines[i] + stripped = line.strip() + + # Check if this is a bare except statement + if stripped == 'except:': + # Check if the previous line is a try block + if i > 0 and 'try:' in lines[i-1]: + # Replace with except Exception: + new_lines.append(line.replace('except:', 'except Exception:')) + modified = True + else: + new_lines.append(line) + else: + new_lines.append(line) + + i += 1 + + if modified: + with open(file_path, 'w') as f: + f.write('\n'.join(new_lines)) + print(f"Fixed {file_path}") + return True + return False + except Exception as e: + print(f"Error processing {file_path}: {e}") + return False + + +def main(): + """Main function""" + if len(sys.argv) > 1: + root = Path(sys.argv[1]) + else: + root = Path('.') + + # Find all Python files + py_files = list(root.rglob('*.py')) + + fixed_count = 0 + for py_file in py_files: + if fix_bare_except(py_file): + fixed_count += 1 + + print(f"\nFixed {fixed_count} files") + + +if __name__ == '__main__': + main()