From 2926542fcdcbb7d3cce4bcb98d726a4881ffa5c5 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Wed, 14 May 2025 11:05:02 +0200 Subject: [PATCH] simplify libwaku error returns (#3399) --- .../requests/discovery_request.nim | 2 +- .../requests/node_lifecycle_request.nim | 6 +++--- .../requests/protocols/lightpush_request.nim | 2 +- .../requests/protocols/relay_request.nim | 19 ++++++++----------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/library/waku_thread/inter_thread_communication/requests/discovery_request.nim b/library/waku_thread/inter_thread_communication/requests/discovery_request.nim index 078a43030..4eb193728 100644 --- a/library/waku_thread/inter_thread_communication/requests/discovery_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/discovery_request.nim @@ -143,7 +143,7 @@ proc process*( of PEER_EXCHANGE: let numValidPeers = (await performPeerExchangeRequestTo(self[].numPeers, waku)).valueOr: error "PEER_EXCHANGE failed", error = error - return err("error calling performPeerExchangeRequestTo: " & $error) + return err($error) return ok($numValidPeers) error "discovery request not handled" diff --git a/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim b/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim index 8a874b681..8d504df89 100644 --- a/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim @@ -92,16 +92,16 @@ proc process*( of CREATE_NODE: waku[] = (await createWaku(self.configJson, self.appCallbacks)).valueOr: error "CREATE_NODE failed", error = error - return err("error processing createWaku request: " & $error) + return err($error) of START_NODE: (await waku.startWaku()).isOkOr: error "START_NODE failed", error = error - return err("problem starting waku: " & $error) + return err($error) of STOP_NODE: try: await waku[].stop() except Exception: error "STOP_NODE failed", error = getCurrentExceptionMsg() - return err("exception stopping node: " & getCurrentExceptionMsg()) + return err(getCurrentExceptionMsg()) return ok("") diff --git a/library/waku_thread/inter_thread_communication/requests/protocols/lightpush_request.nim b/library/waku_thread/inter_thread_communication/requests/protocols/lightpush_request.nim index e7006ad06..f167cd239 100644 --- a/library/waku_thread/inter_thread_communication/requests/protocols/lightpush_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/protocols/lightpush_request.nim @@ -104,6 +104,6 @@ proc process*( ) ).valueOr: error "PUBLISH failed", error = error - return err("LightpushRequest error publishing: " & $error) + return err($error) return ok(msgHashHex) diff --git a/library/waku_thread/inter_thread_communication/requests/protocols/relay_request.nim b/library/waku_thread/inter_thread_communication/requests/protocols/relay_request.nim index 6a437122a..c2f002c44 100644 --- a/library/waku_thread/inter_thread_communication/requests/protocols/relay_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/protocols/relay_request.nim @@ -113,28 +113,25 @@ proc process*( (kind: SubscriptionKind.PubsubSub, topic: $self.pubsubTopic), handler = some(self.relayEventCallback), ).isOkOr: - let errorMsg = "Subscribe failed:" & $error - error "SUBSCRIBE failed", error = errorMsg - return err(errorMsg) + error "SUBSCRIBE failed", error + return err($error) of UNSUBSCRIBE: waku.node.unsubscribe((kind: SubscriptionKind.PubsubSub, topic: $self.pubsubTopic)).isOkOr: - let errorMsg = "Unsubscribe failed:" & $error - error "UNSUBSCRIBE failed", error = errorMsg - return err(errorMsg) + error "UNSUBSCRIBE failed", error + return err($error) of PUBLISH: let msg = self.message.toWakuMessage() let pubsubTopic = $self.pubsubTopic (await waku.node.wakuRelay.publish(pubsubTopic, msg)).isOkOr: - let errorMsg = "Message not sent." & $error - error "PUBLISH failed", error = errorMsg - return err(errorMsg) + error "PUBLISH failed", error + return err($error) let msgHash = computeMessageHash(pubSubTopic, msg).to0xHex return ok(msgHash) of NUM_CONNECTED_PEERS: let numConnPeers = waku.node.wakuRelay.getNumConnectedPeers($self.pubsubTopic).valueOr: - error "NUM_CONNECTED_PEERS failed", error = error + error "NUM_CONNECTED_PEERS failed", error return err($error) return ok($numConnPeers) of LIST_CONNECTED_PEERS: @@ -164,5 +161,5 @@ proc process*( @[protectedShard], uint16(self.clusterId) ) except ValueError: - return err("ADD_PROTECTED_SHARD exception: " & getCurrentExceptionMsg()) + return err(getCurrentExceptionMsg()) return ok("")