From f8395dcd2480e0eab592f997c3f59336f8055fda Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 12 Mar 2026 17:35:41 -0400 Subject: [PATCH] Fix port_idx type coercion and add logging to silent except blocks - port_idx now coerced to int() with 400 on invalid type (prevents string/int mismatch) - api_network and api_links bare except blocks now log errors instead of silently passing Co-Authored-By: Claude Sonnet 4.6 --- app.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 8acdd07..df59a52 100644 --- a/app.py +++ b/app.py @@ -181,7 +181,7 @@ def api_network(): try: return jsonify(json.loads(raw)) except Exception: - pass + logger.error('Failed to parse network_snapshot JSON') return jsonify({'hosts': {}, 'unifi': [], 'updated': None}) @@ -193,7 +193,7 @@ def api_links(): try: return jsonify(json.loads(raw)) except Exception: - pass + logger.error('Failed to parse link_stats JSON') return jsonify({'hosts': {}, 'updated': None}) @@ -261,9 +261,12 @@ def api_diagnose_start(): """Start a link diagnostic job. Returns {job_id}.""" data = request.get_json(silent=True) or {} switch_name = (data.get('switch_name') or '').strip() - port_idx = data.get('port_idx') + try: + port_idx = int(data.get('port_idx')) + except (TypeError, ValueError): + return jsonify({'error': 'port_idx must be an integer'}), 400 - if not switch_name or port_idx is None: + if not switch_name: return jsonify({'error': 'switch_name and port_idx required'}), 400 # Look up switch + port in cached link_stats