fix: replace bare except with except Exception in critical files
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 19s
Blockchain Synchronization Verification / sync-verification (push) Successful in 8s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 8s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 12s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 8s
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Deploy to Testnet / notify-deployment (push) Has been cancelled
Integration Tests / test-service-integration (push) Has started running
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 7s
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
P2P Network Verification / p2p-verification (push) Successful in 10s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 19s
Blockchain Synchronization Verification / sync-verification (push) Successful in 8s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 8s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 12s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 8s
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Deploy to Testnet / notify-deployment (push) Has been cancelled
Integration Tests / test-service-integration (push) Has started running
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 7s
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
P2P Network Verification / p2p-verification (push) Successful in 10s
- Fixed bare except clauses in blockchain-node p2p_network.py - Fixed bare except clauses in blockchain-node rpc/router.py - Fixed bare except clauses in coordinator-api migration scripts - Fixed bare except clause in coordinator-api agent_integration_router.py - Addresses ruff E722 warnings in critical application code - Note: 170 bare except clauses remain in tests/dev/plugins (lower priority)
This commit is contained in:
@@ -557,7 +557,7 @@ class P2PNetworkService:
|
|||||||
writer.close()
|
writer.close()
|
||||||
try:
|
try:
|
||||||
await writer.wait_closed()
|
await writer.wait_closed()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_gpu_count(self) -> int:
|
def _get_gpu_count(self) -> int:
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ def _normalize_transaction_data(tx_data: Dict[str, Any], chain_id: str) -> Dict[
|
|||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
payload = json.loads(payload)
|
payload = json.loads(payload)
|
||||||
except:
|
except Exception:
|
||||||
payload = {}
|
payload = {}
|
||||||
|
|
||||||
if not isinstance(payload, dict):
|
if not isinstance(payload, dict):
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def migrate_all_data():
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
try:
|
try:
|
||||||
value = json.loads(value)
|
value = json.loads(value)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
elif col_name in ['balance', 'price', 'average_job_duration_ms'] and value is not None:
|
elif col_name in ['balance', 'price', 'average_job_duration_ms'] and value is not None:
|
||||||
value = Decimal(str(value))
|
value = Decimal(str(value))
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ def migrate_data():
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
try:
|
try:
|
||||||
value = json.loads(value)
|
value = json.loads(value)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
elif key in ['balance', 'price', 'average_job_duration_ms']:
|
elif key in ['balance', 'price', 'average_job_duration_ms']:
|
||||||
# Handle numeric fields
|
# Handle numeric fields
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ async def get_production_dashboard(
|
|||||||
try:
|
try:
|
||||||
monitoring_manager = AgentMonitoringManager(session)
|
monitoring_manager = AgentMonitoringManager(session)
|
||||||
metrics = await monitoring_manager.get_deployment_metrics(config.id)
|
metrics = await monitoring_manager.get_deployment_metrics(config.id)
|
||||||
except:
|
except Exception:
|
||||||
metrics = {"aggregated_metrics": {}}
|
metrics = {"aggregated_metrics": {}}
|
||||||
|
|
||||||
dashboard_data["deployments"].append(
|
dashboard_data["deployments"].append(
|
||||||
|
|||||||
76
scripts/fix_bare_except.py
Normal file
76
scripts/fix_bare_except.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user