Skip to content

Commit

Permalink
chore: better descriptive log (#2826)
Browse files Browse the repository at this point in the history
* chore: update logs with topic discription & debug msg

* chore: update unit according to error msg

* chore: update rest unit according to error msg

* chore: add content-topic with debug msg
  • Loading branch information
darshankabariya authored Jun 20, 2024
1 parent c483ace commit 94947a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/waku_core/test_namespaced_topics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ suite "Waku Message - Content topics namespacing":
let err = ns.tryError()
check:
err.kind == ParsingErrorKind.InvalidFormat
err.cause == "topic must start with slash"
err.cause == "content-topic '" & topic & "' must start with slash"

test "Parse content topic string - Invalid string: not namespaced":
## Given
Expand Down
6 changes: 4 additions & 2 deletions tests/wakunode_rest/test_rest_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,12 @@ suite "Waku v2 Rest API - Relay":

let client = newRestHttpClient(initTAddress(restAddress, restPort))

let invalidContentTopic = "invalidContentTopic"
# When
let response = await client.relayPostAutoMessagesV1(
RelayWakuMessage(
payload: base64.encode("TEST-PAYLOAD"),
contentTopic: some("invalidContentTopic"),
contentTopic: some(invalidContentTopic),
timestamp: some(int64(2022)),
)
)
Expand All @@ -525,7 +526,8 @@ suite "Waku v2 Rest API - Relay":
response.status == 400
$response.contentType == $MIMETYPE_TEXT
response.data ==
"Failed to publish. Autosharding error: invalid format: topic must start with slash"
"Failed to publish. Autosharding error: invalid format: content-topic '" &
invalidContentTopic & "' must start with slash"

await restServer.stop()
await restServer.closeWait()
Expand Down
3 changes: 3 additions & 0 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ proc setupProtocols(
conf.contentTopics.mapIt(node.wakuSharding.getShard(it).expect("Valid Shard"))
let pubsubTopics = conf.pubsubTopics & shards

debug "Shards created from content topics",
contentTopics = conf.contentTopics, shards = shards

let parsedMaxMsgSize = parseMsgSize(conf.maxMessageSize).valueOr:
return err("failed to parse 'max-num-bytes-msg-size' param: " & $error)

Expand Down
4 changes: 3 additions & 1 deletion waku/waku_core/topics/content_topic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ proc parse*(
## Autosharding adds 1 optional prefix `/<gen#>

if not topic.startsWith("/"):
return err(ParsingError.invalidFormat("topic must start with slash"))
return err(
ParsingError.invalidFormat("content-topic '" & topic & "' must start with slash")
)

let parts = topic[1 ..< topic.len].split("/")

Expand Down

0 comments on commit 94947a8

Please sign in to comment.