fix: don't panic when unserializing json

This commit is contained in:
Richard Ramos 2023-09-27 15:09:35 -04:00
parent e64fb485d9
commit 657d5a2084
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 9 additions and 4 deletions

View File

@ -7,10 +7,15 @@ use std::ffi::{c_char, CStr};
pub fn decode_and_free_response<T: DeserializeOwned>(response_ptr: *mut c_char) -> Result<T> {
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<T> =
serde_json::from_str(response).expect("JsonResponse should always succeed to deserialize");
let response: JsonResponse<T> = serde_json::from_str(response)
.map_err(|err| format!("could not deserialize waku JsonResponse: {}", err))?;
unsafe {
waku_sys::waku_utils_free(response_ptr);

@ -1 +1 @@
Subproject commit 6c34b2714154a1a73b7cbd4df7050342288da463
Subproject commit 30811f4d9203973783a80a552d64ef5b9f719957