mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
fix: libwaku's invalid waku message error handling (#3301)
This commit is contained in:
parent
9bb567eb0e
commit
8275d70f35
@ -20,6 +20,13 @@ func fromJsonNode*(
|
|||||||
T: type JsonMessage, jsonContent: JsonNode
|
T: type JsonMessage, jsonContent: JsonNode
|
||||||
): Result[JsonMessage, string] =
|
): Result[JsonMessage, string] =
|
||||||
# Visit https://rfc.vac.dev/spec/14/ for further details
|
# Visit https://rfc.vac.dev/spec/14/ for further details
|
||||||
|
|
||||||
|
# Check if required fields exist
|
||||||
|
if not jsonContent.hasKey("payload"):
|
||||||
|
return err("Missing required field in WakuMessage: payload")
|
||||||
|
if not jsonContent.hasKey("contentTopic"):
|
||||||
|
return err("Missing required field in WakuMessage: contentTopic")
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
JsonMessage(
|
JsonMessage(
|
||||||
payload: Base64String(jsonContent["payload"].getStr()),
|
payload: Base64String(jsonContent["payload"].getStr()),
|
||||||
|
|||||||
@ -291,18 +291,17 @@ proc waku_relay_publish(
|
|||||||
checkLibwakuParams(ctx, callback, userData)
|
checkLibwakuParams(ctx, callback, userData)
|
||||||
|
|
||||||
let jwm = jsonWakuMessage.alloc()
|
let jwm = jsonWakuMessage.alloc()
|
||||||
|
defer:
|
||||||
|
deallocShared(jwm)
|
||||||
var jsonMessage: JsonMessage
|
var jsonMessage: JsonMessage
|
||||||
try:
|
try:
|
||||||
let jsonContent = parseJson($jwm)
|
let jsonContent = parseJson($jwm)
|
||||||
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
||||||
raise newException(JsonParsingError, $error)
|
raise newException(JsonParsingError, $error)
|
||||||
except JsonParsingError:
|
except JsonParsingError:
|
||||||
deallocShared(jwm)
|
|
||||||
let msg = fmt"Error parsing json message: {getCurrentExceptionMsg()}"
|
let msg = fmt"Error parsing json message: {getCurrentExceptionMsg()}"
|
||||||
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||||
return RET_ERR
|
return RET_ERR
|
||||||
finally:
|
|
||||||
deallocShared(jwm)
|
|
||||||
|
|
||||||
let wakuMessage = jsonMessage.toWakuMessage().valueOr:
|
let wakuMessage = jsonMessage.toWakuMessage().valueOr:
|
||||||
let msg = "Problem building the WakuMessage: " & $error
|
let msg = "Problem building the WakuMessage: " & $error
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user