diff --git a/waku/v2/protocol/waku_lightpush/protocol.nim b/waku/v2/protocol/waku_lightpush/protocol.nim index c62e501092..094f817795 100644 --- a/waku/v2/protocol/waku_lightpush/protocol.nim +++ b/waku/v2/protocol/waku_lightpush/protocol.nim @@ -27,7 +27,7 @@ const WakuLightPushCodec* = "/vac/waku/lightpush/2.0.0-beta1" type WakuLightPushResult*[T] = Result[T, string] - + PushMessageHandler* = proc(peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage): Future[WakuLightPushResult[void]] {.gcsafe, closure.} WakuLightPush* = ref object of LPProtocol @@ -57,7 +57,15 @@ proc initProtocolHandler*(wl: WakuLightPush) = debug "push request", peerId=conn.peerId, requestId=req.requestId, pubsubTopic=pubsubTopic var response: PushResponse - let handleRes = await wl.pushHandler(conn.peerId, pubsubTopic, message) + var handleRes: WakuLightPushResult[void] + try: + handleRes = await wl.pushHandler(conn.peerId, pubsubTopic, message) + except Exception: + response = PushResponse(is_success: false, info: some(getCurrentExceptionMsg())) + waku_lightpush_errors.inc(labelValues = [messagePushFailure]) + error "pushed message handling failed", error= getCurrentExceptionMsg() + + if handleRes.isOk(): response = PushResponse(is_success: true, info: some("OK")) else: @@ -71,10 +79,10 @@ proc initProtocolHandler*(wl: WakuLightPush) = wl.handler = handle wl.codec = WakuLightPushCodec -proc new*(T: type WakuLightPush, - peerManager: PeerManager, +proc new*(T: type WakuLightPush, + peerManager: PeerManager, rng: ref rand.HmacDrbgContext, - pushHandler: PushMessageHandler): T = + pushHandler: PushMessageHandler): T = let wl = WakuLightPush(rng: rng, peerManager: peerManager, pushHandler: pushHandler) wl.initProtocolHandler() return wl diff --git a/waku/v2/protocol/waku_store/protocol.nim b/waku/v2/protocol/waku_store/protocol.nim index fc91f4a724..858bcdd452 100644 --- a/waku/v2/protocol/waku_store/protocol.nim +++ b/waku/v2/protocol/waku_store/protocol.nim @@ -72,7 +72,17 @@ proc initProtocolHandler(ws: WakuStore) = info "received history query", peerId=conn.peerId, requestId=requestId, query=request waku_store_queries.inc() - let responseRes = ws.queryHandler(request) + var responseRes: HistoryResult + try: + responseRes = ws.queryHandler(request) + except Exception: + error "history query failed", peerId= $conn.peerId, requestId=requestId, error=getCurrentExceptionMsg() + + let error = HistoryError(kind: HistoryErrorKind.UNKNOWN).toRPC() + let response = HistoryResponseRPC(error: error) + let rpc = HistoryRPC(requestId: requestId, response: some(response)) + await conn.writeLp(rpc.encode().buffer) + return if responseRes.isErr(): error "history query failed", peerId= $conn.peerId, requestId=requestId, error=responseRes.error