ut0/wait_close now detects errors

Fixes #29
This commit is contained in:
Olivier 'reivilibre' 2021-07-03 08:47:14 +01:00
parent 99d4ff5d6b
commit f08217771c

View File

@ -158,7 +158,19 @@ class Channel:
async def wait_close(self):
try:
await self.recv()
closure = await self.recv()
if not isinstance(closure, dict):
raise ValueError("Closure should be of type dict")
if not closure.get("closure"):
raise ValueError("Closure should have closure: True")
reason = closure.get("reason")
if reason != "Utensil complete":
raise ValueError(
f"Closure was not for the right reason: expected 'Utensil complete'"
f", found {reason}"
)
raise RuntimeError("Message arrived when expecting closure.")
except EOFError:
# expected