From 133ffa92126a45bf8c390270f7859cce16ce76f9 Mon Sep 17 00:00:00 2001 From: Auke Willem Oosterhoff <1565144+OrangeTux@users.noreply.github.com> Date: Wed, 21 Apr 2021 17:15:02 +0200 Subject: [PATCH] Add context to TimeoutErrors (#201) `ChargePoint.call()` raises a `asyncio.TimeoutError` if a call isn't answered withing a given time. However, the `asyncio.TimeoutError` is missing context. The lack of context makes interpreting this exception hard than it should be. This commit add that context. Fixes: #200 --- ocpp/charge_point.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ocpp/charge_point.py b/ocpp/charge_point.py index 5b1ad9e9e..5b50a18a6 100644 --- a/ocpp/charge_point.py +++ b/ocpp/charge_point.py @@ -260,9 +260,15 @@ async def call(self, payload, suppress=True): # a time. async with self._call_lock: await self._send(call.to_json()) - response = \ - await self._get_specific_response(call.unique_id, - self._response_timeout) + try: + response = \ + await self._get_specific_response(call.unique_id, + self._response_timeout) + except asyncio.TimeoutError: + raise asyncio.TimeoutError( + f"Waited {self._response_timeout}s for response on " + f"{call.to_json()}." + ) if response.message_type_id == MessageType.CallError: LOGGER.warning("Received a CALLError: %s'", response)