Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(opensearch_client): improve errors for search deserialization failure (#264)
Will Hutchinson9a50f7410587
diff --git a/rust/cloud-storage/opensearch_client/src/error.rs b/rust/cloud-storage/opensearch_client/src/error.rsindex d5a845b4bb..d16c168084 100644--- a/rust/cloud-storage/opensearch_client/src/error.rs+++ b/rust/cloud-storage/opensearch_client/src/error.rs@@ -11,11 +11,19 @@ pub enum OpensearchClientError {details: String,method: Option<String>,},++ #[error("error deserializing search response. error: {details}, raw_body: {raw_body}")]+ SearchDeserializationFailed { details: String, raw_body: String },++ #[error("unable to grab bytes from http response: {details}")]+ HttpBytesError { details: String },+#[error("unable to serialize into json. method: {method:?} details: {details}")]SerializationFailed {details: String,method: Option<String>,},+#[error("a network error occurred. status_code: {status_code} message: {message}")]NetworkError { status_code: u16, message: String },diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 41284ed86b..134adb89e0 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -205,12 +205,17 @@ pub(crate) async fn search_channel_messages(.map_client_error().await?;- let result = response- .json::<DefaultSearchResponse<ChannelMessageIndex>>()+ let bytes = response+ .bytes().await- .map_err(|e| OpensearchClientError::DeserializationFailed {+ .map_err(|e| OpensearchClientError::HttpBytesError {details: e.to_string(),- method: Some("search_channel".to_string()),+ })?;++ let result: DefaultSearchResponse<ChannelMessageIndex> = serde_json::from_slice(&bytes)+ .map_err(|e| OpensearchClientError::SearchDeserializationFailed {+ details: e.to_string(),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),})?;Ok(resultdiff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rsindex a26c689437..71f24048fc 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs@@ -168,14 +168,20 @@ pub(crate) async fn search_chats(.map_client_error().await?;- let result = response- .json::<DefaultSearchResponse<ChatIndex>>()+ let bytes = response+ .bytes().await- .map_err(|e| OpensearchClientError::DeserializationFailed {+ .map_err(|e| OpensearchClientError::HttpBytesError {details: e.to_string(),- method: Some("search_chats".to_string()),})?;+ let result: DefaultSearchResponse<ChatIndex> = serde_json::from_slice(&bytes).map_err(|e| {+ OpensearchClientError::SearchDeserializationFailed {+ details: e.to_string(),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),+ }+ })?;+Ok(result.hits.hitsdiff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex 3d06b9696a..45e5aee24e 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -151,12 +151,19 @@ pub(crate) async fn search_documents(.map_client_error().await?;- let result = response- .json::<DefaultSearchResponse<DocumentIndex>>()+ let bytes = response+ .bytes().await- .map_err(|e| OpensearchClientError::DeserializationFailed {+ .map_err(|e| OpensearchClientError::HttpBytesError {details: e.to_string(),- method: Some("search_documents".to_string()),+ })?;++ let result: DefaultSearchResponse<DocumentIndex> =+ serde_json::from_slice(&bytes).map_err(|e| {+ OpensearchClientError::SearchDeserializationFailed {+ details: e.to_string(),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),+ }})?;Ok(resultdiff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex cac555ac4d..f8e26f09a5 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -256,12 +256,19 @@ pub(crate) async fn search_emails(.map_client_error().await?;- let result = response- .json::<DefaultSearchResponse<EmailIndex>>()+ let bytes = response+ .bytes().await- .map_err(|e| OpensearchClientError::DeserializationFailed {+ .map_err(|e| OpensearchClientError::HttpBytesError {details: e.to_string(),- method: Some("search_emails".to_string()),+ })?;++ let result: DefaultSearchResponse<EmailIndex> =+ serde_json::from_slice(&bytes).map_err(|e| {+ OpensearchClientError::SearchDeserializationFailed {+ details: e.to_string(),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),+ }})?;Ok(resultdiff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rsindex 737330db05..480b67b8a4 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs@@ -149,19 +149,17 @@ pub(crate) async fn search_projects(.map_client_error().await?;- let json_value: serde_json::Value =- response- .json()- .await- .map_err(|e| OpensearchClientError::DeserializationFailed {- details: e.to_string(),- method: Some("search_projects".to_string()),- })?;-- let result: SearchResponse<ProjectIndex> = serde_json::from_value(json_value).map_err(|e| {- OpensearchClientError::DeserializationFailed {+ let bytes = response+ .bytes()+ .await+ .map_err(|e| OpensearchClientError::HttpBytesError {+ details: e.to_string(),+ })?;++ let result: SearchResponse<ProjectIndex> = serde_json::from_slice(&bytes).map_err(|e| {+ OpensearchClientError::SearchDeserializationFailed {details: e.to_string(),- method: Some("search_projects".to_string()),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),}})?;diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex c4b0d3da42..9fd6387a42 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -587,12 +587,17 @@ pub(crate) async fn search_unified(.map_client_error().await?;- let result = response- .json::<DefaultSearchResponse<UnifiedSearchIndex>>()+ let bytes = response+ .bytes().await- .map_err(|e| OpensearchClientError::DeserializationFailed {+ .map_err(|e| OpensearchClientError::HttpBytesError {details: e.to_string(),- method: Some("search_unified".to_string()),+ })?;++ let result: DefaultSearchResponse<UnifiedSearchIndex> = serde_json::from_slice(&bytes)+ .map_err(|e| OpensearchClientError::SearchDeserializationFailed {+ details: e.to_string(),+ raw_body: String::from_utf8_lossy(&bytes).to_string(),})?;Ok(result.hits.hits.into_iter().map(|h| h.into()).collect())diff --git a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rsindex 921e879989..06b7ba4267 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs@@ -23,6 +23,7 @@ pub(crate) async fn upsert_channel_message(args: &UpsertChannelMessageArgs,) -> Result<()> {let id = format!("{}:{}", args.channel_id, args.message_id);+let response = client.index(opensearch::IndexParts::IndexId(CHANNEL_INDEX, &id)).body(args)