Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Better feedback invalid content topic #2254

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/waku_core/test_namespaced_topics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite "Waku Message - Content topics namespacing":
let err = ns.tryError()
check:
err.kind == ParsingErrorKind.InvalidFormat
err.cause == "invalid topic structure"
err.cause == "Invalid content topic structure. Expected either /<application>/<version>/<topic-name>/<encoding> or /<gen>/<application>/<version>/<topic-name>/<encoding>"

test "Parse content topic string - Invalid string: missing encoding part":
## Given
Expand All @@ -104,7 +104,7 @@ suite "Waku Message - Content topics namespacing":
let err = ns.tryError()
check:
err.kind == ParsingErrorKind.InvalidFormat
err.cause == "invalid topic structure"
err.cause == "Invalid content topic structure. Expected either /<application>/<version>/<topic-name>/<encoding> or /<gen>/<application>/<version>/<topic-name>/<encoding>"

test "Parse content topic string - Invalid string: wrong extra parts":
## Given
Expand Down
8 changes: 5 additions & 3 deletions waku/waku_core/topics/content_topic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ proc parse*(T: type NsContentTopic, topic: ContentTopic|string): ParsingResult[N
of 4:
let app = parts[0]
if app.len == 0:
return err(ParsingError.missingPart("appplication"))
return err(ParsingError.missingPart("application"))

let ver = parts[1]
if ver.len == 0:
Expand All @@ -100,7 +100,7 @@ proc parse*(T: type NsContentTopic, topic: ContentTopic|string): ParsingResult[N

let app = parts[1]
if app.len == 0:
return err(ParsingError.missingPart("appplication"))
return err(ParsingError.missingPart("application"))

let ver = parts[2]
if ver.len == 0:
Expand All @@ -116,7 +116,9 @@ proc parse*(T: type NsContentTopic, topic: ContentTopic|string): ParsingResult[N

return ok(NsContentTopic.init(some(gen), app, ver, name, enc))
else:
return err(ParsingError.invalidFormat("invalid topic structure"))

let errMsg = "Invalid content topic structure. Expected either /<application>/<version>/<topic-name>/<encoding> or /<gen>/<application>/<version>/<topic-name>/<encoding>"
return err(ParsingError.invalidFormat(errMsg))

# Content topic compatibility

Expand Down
Loading