From 72a1f8c7242a55cdd1a35aa18c831ea49b2edf10 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:11:33 +0100 Subject: [PATCH] chore: Better feedback invalid content topic (#2254) * typo correction appplication -> application * content_topic.nim: better feedback to user when wrong topic is passed * test_namespaced_topics.nim: updating tests accordingly --- tests/waku_core/test_namespaced_topics.nim | 4 ++-- waku/waku_core/topics/content_topic.nim | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/waku_core/test_namespaced_topics.nim b/tests/waku_core/test_namespaced_topics.nim index 91f9b02507..46145999ae 100644 --- a/tests/waku_core/test_namespaced_topics.nim +++ b/tests/waku_core/test_namespaced_topics.nim @@ -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 //// or /////" test "Parse content topic string - Invalid string: missing encoding part": ## Given @@ -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 //// or /////" test "Parse content topic string - Invalid string: wrong extra parts": ## Given diff --git a/waku/waku_core/topics/content_topic.nim b/waku/waku_core/topics/content_topic.nim index 16fbcf4b5a..16635ebba9 100644 --- a/waku/waku_core/topics/content_topic.nim +++ b/waku/waku_core/topics/content_topic.nim @@ -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: @@ -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: @@ -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 //// or /////" + return err(ParsingError.invalidFormat(errMsg)) # Content topic compatibility