From 657d5a20847562ccbca9140aa5f2e0d7e6db1e57 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 27 Sep 2023 15:09:35 -0400 Subject: [PATCH] fix: don't panic when unserializing json --- waku-bindings/src/utils.rs | 11 ++++++++--- waku-sys/vendor | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/waku-bindings/src/utils.rs b/waku-bindings/src/utils.rs index 4744c46..e1a3a17 100644 --- a/waku-bindings/src/utils.rs +++ b/waku-bindings/src/utils.rs @@ -7,10 +7,15 @@ use std::ffi::{c_char, CStr}; pub fn decode_and_free_response(response_ptr: *mut c_char) -> Result { let response = unsafe { CStr::from_ptr(response_ptr) } .to_str() - .expect("Response should always succeed to load to a &str"); + .map_err(|err| { + format!( + "could not retrieve response from pointer returned by waku: {}", + err + ) + })?; - let response: JsonResponse = - serde_json::from_str(response).expect("JsonResponse should always succeed to deserialize"); + let response: JsonResponse = serde_json::from_str(response) + .map_err(|err| format!("could not deserialize waku JsonResponse: {}", err))?; unsafe { waku_sys::waku_utils_free(response_ptr); diff --git a/waku-sys/vendor b/waku-sys/vendor index 6c34b27..30811f4 160000 --- a/waku-sys/vendor +++ b/waku-sys/vendor @@ -1 +1 @@ -Subproject commit 6c34b2714154a1a73b7cbd4df7050342288da463 +Subproject commit 30811f4d9203973783a80a552d64ef5b9f719957