chore: Enhance feedback on error cli (#3405)

* better error detail
* rm duplicated block
This commit is contained in:
Ivan FB 2025-05-13 09:13:28 +02:00 committed by GitHub
parent 094a68e41d
commit b435b51c4e
5 changed files with 26 additions and 35 deletions

View File

@ -134,13 +134,13 @@ proc updateENRShards(
): Result[void, string] =
## Add or remove shards from the Discv5 ENR
let newShardOp = topicsToRelayShards(newTopics).valueOr:
return err("ENR update failed: " & error)
return err("ENR update failed topicsToRelayShards: " & error)
let newShard = newShardOp.valueOr:
return ok()
let typedRecord = wd.protocol.localNode.record.toTyped().valueOr:
return err("ENR update failed: " & $error)
return err("ENR update failed toTyped: " & $error)
let currentShardsOp = typedRecord.relaySharding()
@ -149,17 +149,17 @@ proc updateENRShards(
let currentShard = currentShardsOp.get()
if currentShard.clusterId != newShard.clusterId:
return err("ENR update failed: clusterId id mismatch")
return err("ENR update failed: clusterId id mismatch in add")
RelayShards.init(
currentShard.clusterId, currentShard.shardIds & newShard.shardIds
).valueOr:
return err("ENR update failed: " & error)
return err("ENR update failed RelayShards.init in add: " & error)
elif not add and currentShardsOp.isSome():
let currentShard = currentShardsOp.get()
if currentShard.clusterId != newShard.clusterId:
return err("ENR update failed: clusterId id mismatch")
return err("ENR update failed: clusterId id mismatch in not add")
let currentSet = toHashSet(currentShard.shardIds)
let newSet = toHashSet(newShard.shardIds)
@ -170,7 +170,7 @@ proc updateENRShards(
return err("ENR update failed: cannot remove all shards")
RelayShards.init(currentShard.clusterId, indices).valueOr:
return err("ENR update failed: " & error)
return err("ENR update failed RelayShards.init in not add: " & error)
elif add and currentShardsOp.isNone():
newShard
else:
@ -181,12 +181,12 @@ proc updateENRShards(
(ShardingBitVectorEnrField, resultShard.toBitVector())
else:
let list = resultShard.toIndicesList().valueOr:
return err("ENR update failed: " & $error)
return err("ENR update failed toIndicesList: " & $error)
(ShardingIndicesListEnrField, list)
wd.protocol.updateRecord([(field, value)]).isOkOr:
return err("ENR update failed: " & $error)
return err("ENR update failed updateRecord: " & $error)
return ok()

View File

@ -70,7 +70,7 @@ type WakuNodeConf* = object
.}: logging.LogFormat
rlnRelayCredPath* {.
desc: "The path for peristing rln-relay credential",
desc: "The path for persisting rln-relay credential",
defaultValue: "",
name: "rln-relay-cred-path"
.}: string

View File

@ -177,7 +177,7 @@ proc new*(
var deliveryMonitor: DeliveryMonitor
if wakuConf.p2pReliability:
if wakuConf.remoteStoreNode.isNone():
return err("A remoteStoreNode should be set when reliability mode is on")
return err("A storenode should be set when reliability mode is on")
let deliveryMonitorRes = DeliveryMonitor.new(
node.wakuStoreClient, node.wakuRelay, node.wakuLightpushClient,
@ -222,7 +222,7 @@ proc getPorts(
proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] =
var conf = waku[].conf
let (tcpPort, websocketPort) = getPorts(waku[].node.switch.peerInfo.listenAddrs).valueOr:
return err("Could not retrieve ports " & error)
return err("Could not retrieve ports: " & error)
if tcpPort.isSome():
conf.networkConf.p2pTcpPort = tcpPort.get()
@ -246,7 +246,7 @@ proc updateEnr(waku: ptr Waku): Result[void, string] =
return err("ENR setup failed: " & error)
if isClusterMismatched(record, waku[].conf.clusterId):
return err("cluster id mismatch configured shards")
return err("cluster-id mismatch configured shards")
waku[].node.enr = record

View File

@ -164,7 +164,7 @@ proc logConf*(conf: WakuConf) =
proc validateNodeKey(wakuConf: WakuConf): Result[void, string] =
wakuConf.nodeKey.getPublicKey().isOkOr:
return err("Node key is invalid")
return err("nodekey param is invalid")
return ok()
proc validateShards(wakuConf: WakuConf): Result[void, string] =
@ -187,58 +187,52 @@ proc validateShards(wakuConf: WakuConf): Result[void, string] =
proc validateNoEmptyStrings(wakuConf: WakuConf): Result[void, string] =
if wakuConf.networkConf.dns4DomainName.isSome() and
isEmptyOrWhiteSpace(wakuConf.networkConf.dns4DomainName.get().string):
return err("dns4DomainName is an empty string, set it to none(string) instead")
return err("dns4-domain-name is an empty string, set it to none(string) instead")
if isEmptyOrWhiteSpace(wakuConf.relayServiceRatio):
return err("relayServiceRatio is an empty string")
return err("relay-service-ratio is an empty string")
for sn in wakuConf.staticNodes:
if isEmptyOrWhiteSpace(sn):
return err("staticNodes contain an empty string")
return err("staticnode contain an empty string")
if wakuConf.remoteStoreNode.isSome() and
isEmptyOrWhiteSpace(wakuConf.remoteStoreNode.get()):
return err("remoteStoreNode is an empty string, set it to none(string) instead")
return err("storenode is an empty string, set it to none(string) instead")
if wakuConf.remoteLightPushNode.isSome() and
isEmptyOrWhiteSpace(wakuConf.remoteLightPushNode.get()):
return err("remoteLightPushNode is an empty string, set it to none(string) instead")
return err("lightpushnode is an empty string, set it to none(string) instead")
if wakuConf.remotePeerExchangeNode.isSome() and
isEmptyOrWhiteSpace(wakuConf.remotePeerExchangeNode.get()):
return
err("remotePeerExchangeNode is an empty string, set it to none(string) instead")
return err("peer-exchange-node is an empty string, set it to none(string) instead")
if wakuConf.remoteFilterNode.isSome() and
isEmptyOrWhiteSpace(wakuConf.remoteFilterNode.get()):
return
err("remotePeerExchangeNode is an empty string, set it to none(string) instead")
return err("filternode is an empty string, set it to none(string) instead")
if wakuConf.dnsDiscoveryConf.isSome() and
isEmptyOrWhiteSpace(wakuConf.dnsDiscoveryConf.get().enrTreeUrl):
return err("dnsDiscoveryConf.enrTreeUrl is an empty string")
return err("dns-discovery-url is an empty string")
# TODO: rln relay config should validate itself
if wakuConf.rlnRelayConf.isSome():
let rlnRelayConf = wakuConf.rlnRelayConf.get()
if isEmptyOrWhiteSpace(rlnRelayConf.treePath):
return err("rlnRelayConf.treepath is an empty string")
return err("rln-relay-tree-path is an empty string")
if rlnRelayConf.ethClientUrls.len == 0:
return err("rlnRelayConf.ethClientUrls is empty")
return err("rln-relay-eth-client-address is empty")
if isEmptyOrWhiteSpace(rlnRelayConf.ethContractAddress):
return err("rlnRelayConf.ethContractAddress is an empty string")
return err("rln-relay-eth-contract-address is an empty string")
if rlnRelayConf.creds.isSome():
let creds = rlnRelayConf.creds.get()
if isEmptyOrWhiteSpace(creds.path):
return err (
"rlnRelayConf.creds.path is an empty string, set rlnRelayConf.creds it to none instead"
)
return err ("rln-relay-cred-path is an empty string")
if isEmptyOrWhiteSpace(creds.password):
return err (
"rlnRelayConf.creds.password is an empty string, set rlnRelayConf.creds to none instead"
)
return err ("rln-relay-cred-password is an empty string")
return ok()

View File

@ -335,9 +335,6 @@ method generateProof*(
let message_id = uint64ToField(messageId)
var path_elements = newSeq[byte](0)
if (g.merkleProofCache.len mod 32) != 0:
return err("Invalid merkle proof cache length")
let identity_path_index = uint64ToIndex(g.membershipIndex.get(), 20)
for i in 0 ..< g.merkleProofCache.len div 32:
let chunk = g.merkleProofCache[i * 32 .. (i + 1) * 32 - 1]