From 6b0d3edecccd9fd348b2d666806ea64e9acaec99 Mon Sep 17 00:00:00 2001 From: sugyan Date: Sun, 6 Jul 2025 23:08:23 +0900 Subject: [PATCH] fix: Improve error handling in types conversion - Add SerdeJson error variant to Error enum - Replace unwrap() with proper error propagation in try_from_unknown --- atrium-api/src/error.rs | 2 ++ atrium-api/src/types.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/atrium-api/src/error.rs b/atrium-api/src/error.rs index 836c27cb..ddd60230 100644 --- a/atrium-api/src/error.rs +++ b/atrium-api/src/error.rs @@ -6,6 +6,8 @@ use thiserror::Error; pub enum Error { #[error(transparent)] IpldCoreSerde(#[from] ipld_core::serde::SerdeError), + #[error(transparent)] + SerdeJson(#[from] serde_json::Error), #[error("not allowed in ATProtocol")] NotAllowed, } diff --git a/atrium-api/src/types.rs b/atrium-api/src/types.rs index 04741235..3a3a2b3c 100644 --- a/atrium-api/src/types.rs +++ b/atrium-api/src/types.rs @@ -276,7 +276,7 @@ where // // For the time being, until this problem is resolved, use the workaround of serializing once to a json string and then deserializing it. let json = serde_json::to_vec(&value).unwrap(); - Ok(serde_json::from_slice(&json).unwrap()) + Ok(serde_json::from_slice(&json)?) } }