1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-02 13:29:49 +00:00

bitbake: asyncrpc: Add InvokeError

Adds support for Invocation Errors (that is, errors raised by the actual
RPC call instead of at the protocol level) to propagate across the
connection. If a server RPC call raises an InvokeError, it will be sent
across the connection and then raised on the client side also. The
connection is still terminated on this error.

(Bitbake rev: 50ee68175e7cf20a32bfbb176db2c47d7859da04)

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Watt
2023-11-03 08:26:28 -06:00
committed by Richard Purdie
parent e31396eb1c
commit dabed6288a
4 changed files with 22 additions and 4 deletions
+1
View File
@@ -12,4 +12,5 @@ from .exceptions import (
ClientError, ClientError,
ServerError, ServerError,
ConnectionClosedError, ConnectionClosedError,
InvokeError,
) )
+8 -2
View File
@@ -11,7 +11,7 @@ import os
import socket import socket
import sys import sys
from .connection import StreamConnection, WebsocketConnection, DEFAULT_MAX_CHUNK from .connection import StreamConnection, WebsocketConnection, DEFAULT_MAX_CHUNK
from .exceptions import ConnectionClosedError from .exceptions import ConnectionClosedError, InvokeError
class AsyncClient(object): class AsyncClient(object):
@@ -93,12 +93,18 @@ class AsyncClient(object):
await self.close() await self.close()
count += 1 count += 1
def check_invoke_error(self, msg):
if isinstance(msg, dict) and "invoke-error" in msg:
raise InvokeError(msg["invoke-error"]["message"])
async def invoke(self, msg): async def invoke(self, msg):
async def proc(): async def proc():
await self.socket.send_message(msg) await self.socket.send_message(msg)
return await self.socket.recv_message() return await self.socket.recv_message()
return await self._send_wrapper(proc) result = await self._send_wrapper(proc)
self.check_invoke_error(result)
return result
async def ping(self): async def ping(self):
return await self.invoke({"ping": {}}) return await self.invoke({"ping": {}})
+4
View File
@@ -9,6 +9,10 @@ class ClientError(Exception):
pass pass
class InvokeError(Exception):
pass
class ServerError(Exception): class ServerError(Exception):
pass pass
+9 -2
View File
@@ -14,7 +14,7 @@ import sys
import multiprocessing import multiprocessing
import logging import logging
from .connection import StreamConnection, WebsocketConnection from .connection import StreamConnection, WebsocketConnection
from .exceptions import ClientError, ServerError, ConnectionClosedError from .exceptions import ClientError, ServerError, ConnectionClosedError, InvokeError
class ClientLoggerAdapter(logging.LoggerAdapter): class ClientLoggerAdapter(logging.LoggerAdapter):
@@ -76,7 +76,14 @@ class AsyncServerConnection(object):
d = await self.socket.recv_message() d = await self.socket.recv_message()
if d is None: if d is None:
break break
response = await self.dispatch_message(d) try:
response = await self.dispatch_message(d)
except InvokeError as e:
await self.socket.send_message(
{"invoke-error": {"message": str(e)}}
)
break
if response is not self.NO_RESPONSE: if response is not self.NO_RESPONSE:
await self.socket.send_message(response) await self.socket.send_message(response)