{"record":{"id":"fce91549d464e68c","repo":"ruvnet/RuView","slug":"router-router-id-not-found-fce915","errorCode":null,"errorMessage":"Router {router_id} not found","messagePattern":"Router (.+?) not found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/services/hardware_service.py","lineNumber":308,"sourceCode":"            time_diffs = []\n            for i in range(1, len(recent_samples)):\n                try:\n                    t1 = datetime.fromisoformat(recent_samples[i-1][\"timestamp\"])\n                    t2 = datetime.fromisoformat(recent_samples[i][\"timestamp\"])\n                    diff = (t2 - t1).total_seconds()\n                    if diff > 0:\n                        time_diffs.append(diff)\n                except Exception:\n                    continue\n            \n            if time_diffs:\n                avg_interval = sum(time_diffs) / len(time_diffs)\n                self.stats[\"average_sample_rate\"] = 1.0 / avg_interval if avg_interval > 0 else 0.0\n    \n    async def get_router_status(self, router_id: str) -> Dict[str, Any]:\n        \"\"\"Get status of a specific router.\"\"\"\n        if router_id not in self.router_interfaces:\n            raise ValueError(f\"Router {router_id} not found\")\n        \n        interface = self.router_interfaces[router_id]\n        \n        try:\n            is_healthy = await interface.check_health()\n            status = await interface.get_status()\n            \n            return {\n                \"router_id\": router_id,\n                \"healthy\": is_healthy,\n                \"connected\": status.get(\"connected\", False),\n                \"last_data_time\": status.get(\"last_data_time\"),\n                \"error_count\": status.get(\"error_count\", 0),\n                \"configuration\": status.get(\"configuration\", {})\n            }\n            \n        except Exception as e:\n            return {","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/services/hardware_service.py#L290-L326","documentation":"HardwareService.get_router_status() looks up router_id in the in-memory router_interfaces mapping, which is populated when routers are registered during service initialization. An unknown id raises ValueError immediately, before any hardware I/O. In practice this means the router was never registered (initialize not run or failed for that router) or the id string does not match the configured one.","triggerScenarios":"Calling get_router_status('router_2') when the service only registered 'router_1'; querying after a failed initialize() that left router_interfaces empty; passing an id with different casing or whitespace than configured.","commonSituations":"API handlers forwarding user-supplied router ids without validation; config drift where .env lists fewer routers than the dashboard expects; calling status right after process start before initialize() completes.","solutions":["List what is actually registered: read service.router_interfaces.keys() or the service's get_status() output, and use one of those ids.","Ensure the service lifecycle completed: 'await hardware_service.initialize()' before querying, and check last_error for registration failures.","Correct the router id in the caller/config (exact string, correct case).","If a router is genuinely missing, add it to the hardware configuration so initialize() registers it."],"exampleFix":"# before\nstatus = await hardware_service.get_router_status('router_2')  # ValueError\n\n# after\nif 'router_2' not in hardware_service.router_interfaces:\n    raise KeyError(f\"unknown router; registered: {sorted(hardware_service.router_interfaces)}\")\nstatus = await hardware_service.get_router_status('router_2')","handlingStrategy":"validation","validationCode":"known = set(hardware_service.router_interfaces)\nif router_id not in known:\n    raise KeyError(f'unknown router {router_id}; registered: {sorted(known)}')\nstatus = await hardware_service.get_router_status(router_id)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expose the registered router ids via your API (derived from router_interfaces) and have clients use those ids.","Validate user-supplied router ids at the request boundary before touching the service.","Ensure initialize() completed (and check last_error) before serving router status queries."],"tags":["hardware","router","validation","service","asyncio"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}