Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

refactor: use anyhow::bail! (#1869)

Will Hutchinsonf2609f8cb6a2
diff --git a/rust/cloud-storage/ai/src/structured_output_v2.rs b/rust/cloud-storage/ai/src/structured_output_v2.rs
index 662ed43fe8..4233ef8a29 100644
--- a/rust/cloud-storage/ai/src/structured_output_v2.rs
+++ b/rust/cloud-storage/ai/src/structured_output_v2.rs
@@ -29,9 +29,9 @@ where
}
Err(e) => {
tracing::error!("API call failed with error: {:?}", e);
- return Err(anyhow::anyhow!("API call failed: {}", e));
+ anyhow::bail!("API call failed: {}", e);
}
}
- Err(anyhow::anyhow!("Expected structured response"))
+ anyhow::bail!("Expected structured response")
}
diff --git a/rust/cloud-storage/connection_gateway/src/service/connection.rs b/rust/cloud-storage/connection_gateway/src/service/connection.rs
index 57df7cb88d..beea72f66e 100644
--- a/rust/cloud-storage/connection_gateway/src/service/connection.rs
+++ b/rust/cloud-storage/connection_gateway/src/service/connection.rs
@@ -202,12 +202,12 @@ impl ConnectionManager {
pub async fn send_message(&self, id: &str, message: Message) -> Result<()> {
let sender = match self.connections.get(id) {
Some(connection) => connection.sender.clone(),
- None => return Err(anyhow::anyhow!("connection not found")),
+ None => anyhow::bail!("connection not found"),
};
if let Err(err) = sender.send(OutgoingMessage::Message(message)).await {
self.remove_connection(id).await?;
- return Err(anyhow::anyhow!("failed to send message: {}", err));
+ anyhow::bail!("failed to send message: {}", err);
}
Ok(())
diff --git a/rust/cloud-storage/convert_service/src/process/convert.rs b/rust/cloud-storage/convert_service/src/process/convert.rs
index ac3f0c99a5..f09f928f82 100644
--- a/rust/cloud-storage/convert_service/src/process/convert.rs
+++ b/rust/cloud-storage/convert_service/src/process/convert.rs
@@ -42,7 +42,7 @@ pub async fn process_message(
.cleanup_message(message)
.await
.context("failed to cleanup message")?;
- return Err(anyhow::anyhow!("required message attributes not found"));
+ anyhow::bail!("required message attributes not found");
};
tracing::info!(job_id=%job_id, "message attributes");
@@ -56,7 +56,7 @@ pub async fn process_message(
.cleanup_message(message)
.await
.context("failed to cleanup message")?;
- return Err(anyhow::anyhow!("message body not provided"));
+ anyhow::bail!("message body not provided");
};
tracing::info!(job_id=%job_id, message_body=?req, "message body");
@@ -210,7 +210,7 @@ pub async fn convert(
},
Err(err) => {
tracing::error!(job_id=%job_id, error=?err, "fork failed");
- return Err(anyhow::anyhow!("fork failed"));
+ anyhow::bail!("fork failed");
}
}
@@ -265,7 +265,7 @@ pub async fn convert(
if let Err(e) = cleanup_folder(job_id) {
tracing::error!(error=?e, job_id=%job_id, "unable to cleanup folder");
}
- return Err(anyhow::anyhow!("conversion failed"));
+ anyhow::bail!("conversion failed");
}
let file_content = std::fs::read(out_file_path).context("unable to read result file")?;
diff --git a/rust/cloud-storage/document_cognition_service/load-test/src/main.rs b/rust/cloud-storage/document_cognition_service/load-test/src/main.rs
index 51c818fa4c..eb1d4c0849 100644
--- a/rust/cloud-storage/document_cognition_service/load-test/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/load-test/src/main.rs
@@ -267,7 +267,7 @@ async fn main() -> anyhow::Result<()> {
.to_string();
if std::env::var("TOKEN").is_err() {
- return Err(anyhow!("please set `TOKEN` env var with your macro-token"));
+ anyhow::bail!("please set `TOKEN` env var with your macro-token");
}
let config = Arc::new(config::read(&config_path)?);
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/export_document.rs b/rust/cloud-storage/document_storage_service/src/api/documents/export_document.rs
index 77ea164b33..cfc7c62358 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/export_document.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/export_document.rs
@@ -140,7 +140,7 @@ async fn export_basic_document(
match result {
LocationResponseData::PresignedUrl(presigned_url) => Ok(presigned_url),
LocationResponseData::PresignedUrls(_) => {
- Err(anyhow::anyhow!("expected presigned url type only"))
+ anyhow::bail!("expected presigned url type only")
}
}
}
@@ -171,7 +171,7 @@ async fn export_docx_document(state: &ApiContext, document_id: &str) -> anyhow::
.await;
if downloaded_bom_parts.iter().any(|r| r.is_err()) {
- return Err(anyhow::anyhow!("unable to download bom parts"));
+ anyhow::bail!("unable to download bom parts");
}
let downloaded_bom_parts: Vec<(String, Vec<u8>)> = downloaded_bom_parts
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/location.rs b/rust/cloud-storage/document_storage_service/src/api/documents/location.rs
index d8404ed0c1..7b2c467a8f 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/location.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/location.rs
@@ -1,5 +1,4 @@
use crate::api::context::ApiContext;
-use anyhow::anyhow;
use macro_middleware::cloud_storage::ensure_access::document::DocumentAccessExtractor;
use models_permissions::share_permission::access_level::ViewAccessLevel;
use rayon::prelude::*;
@@ -148,7 +147,7 @@ async fn get_editable_url(
tracing::trace!("checking if file exists in s3, key: {}", document_key);
let exists = verify_file_exists(&state.s3_client, &document_key).await?;
if !exists {
- return Err(anyhow!(DOCUMENT_DOES_NOT_EXIST));
+ anyhow::bail!(DOCUMENT_DOES_NOT_EXIST);
}
}
@@ -210,7 +209,7 @@ pub(in crate::api::documents) async fn get_static_url(
tracing::trace!("checking if file exists in s3, key: {}", document_key);
let exists = verify_file_exists(&state.s3_client, &document_key).await?;
if !exists {
- return Err(anyhow!(DOCUMENT_DOES_NOT_EXIST));
+ anyhow::bail!(DOCUMENT_DOES_NOT_EXIST);
}
}
@@ -263,7 +262,7 @@ async fn get_converted_docx_url(
tracing::trace!("checking if file exists in s3, key: {}", document_key);
let exists = verify_file_exists(&state.s3_client, &document_key).await?;
if !exists {
- return Err(anyhow!(DOCUMENT_DOES_NOT_EXIST));
+ anyhow::bail!(DOCUMENT_DOES_NOT_EXIST);
}
}
@@ -354,7 +353,7 @@ async fn get_docx_urls(
.collect();
if shas.len() != presigned_urls.len() {
- return Err(anyhow!("unable to generate presigned urls"));
+ anyhow::bail!("unable to generate presigned urls");
}
tracing::debug!(elapsed = ?start_presigned_urls.elapsed(), "got presigned urls");
diff --git a/rust/cloud-storage/document_storage_service_client/src/delete.rs b/rust/cloud-storage/document_storage_service_client/src/delete.rs
index 757ec6e29f..5ee48f2a43 100644
--- a/rust/cloud-storage/document_storage_service_client/src/delete.rs
+++ b/rust/cloud-storage/document_storage_service_client/src/delete.rs
@@ -20,7 +20,7 @@ impl DocumentStorageServiceClient {
status=%status_code,
"unexpected response from document storage service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
Ok(())
diff --git a/rust/cloud-storage/document_storage_service_client/src/document.rs b/rust/cloud-storage/document_storage_service_client/src/document.rs
index 72f1b82822..cb61fa7de1 100644
--- a/rust/cloud-storage/document_storage_service_client/src/document.rs
+++ b/rust/cloud-storage/document_storage_service_client/src/document.rs
@@ -63,7 +63,7 @@ impl DocumentStorageServiceClient {
status=%status_code,
"unexpected response from document storage service"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let doc_data: DocumentBasic = res.json().await?;
@@ -188,7 +188,7 @@ impl DocumentStorageServiceClient {
status=%status_code,
"unexpected response from document storage service"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let doc_data: DocumentBasic = res.json().await?;
@@ -221,7 +221,7 @@ impl DocumentStorageServiceClient {
document_id=%document_id,
"external API error when fetching document location"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let location_data = res.json::<LocationResponseV3>().await?;
@@ -254,7 +254,7 @@ impl DocumentStorageServiceClient {
document_id=%document_id,
"external API error when fetching document text"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let response_data = res.json::<GetDocumentTextResponse>().await?;
@@ -280,11 +280,7 @@ impl DocumentStorageServiceClient {
.await
.unwrap_or_else(|_| "<failed to read body>".into());
- return Err(anyhow::anyhow!(
- "get documents metadata failed: {} - {}",
- status,
- text
- ));
+ anyhow::bail!("get documents metadata failed: {} - {}", status, text);
}
let data = response
@@ -351,7 +347,7 @@ impl DocumentStorageServiceClient {
user_id=%user_id,
"error when listing documents with access"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let response_data = res.json::<ListDocumentsWithAccessResponse>().await?;
diff --git a/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs b/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs
index e2125894b3..5935349eab 100644
--- a/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs
+++ b/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs
@@ -36,7 +36,7 @@ impl DocumentStorageServiceClient {
status=%status_code,
"unexpected response from document storage service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
}
}
diff --git a/rust/cloud-storage/document_storage_service_client/src/upload.rs b/rust/cloud-storage/document_storage_service_client/src/upload.rs
index cce9826559..bec2d74b6c 100644
--- a/rust/cloud-storage/document_storage_service_client/src/upload.rs
+++ b/rust/cloud-storage/document_storage_service_client/src/upload.rs
@@ -42,11 +42,7 @@ impl DocumentStorageServiceClient {
.await
.unwrap_or_else(|_| "<failed to read body>".into());
- return Err(anyhow::anyhow!(
- "upload unnested failed: {} - {}",
- status,
- text
- ));
+ anyhow::bail!("upload unnested failed: {} - {}", status, text);
}
let data = match response
@@ -55,7 +51,7 @@ impl DocumentStorageServiceClient {
{
Ok(upload_response_data) => upload_response_data.data,
Err(_) => {
- return Err(anyhow::anyhow!("unable to parse response"));
+ anyhow::bail!("unable to parse response");
}
};
@@ -89,17 +85,13 @@ impl DocumentStorageServiceClient {
.await
.unwrap_or_else(|_| "<failed to read body>".into());
- return Err(anyhow::anyhow!(
- "mark uploaded failed: {} - {}",
- status,
- text
- ));
+ anyhow::bail!("mark uploaded failed: {} - {}", status, text);
}
let data = match response.json::<MarkProjectUploadedResponse>().await {
Ok(data) => data,
Err(_) => {
- return Err(anyhow::anyhow!("unable to parse response"));
+ anyhow::bail!("unable to parse response");
}
};
diff --git a/rust/cloud-storage/document_text_extractor/src/model/key.rs b/rust/cloud-storage/document_text_extractor/src/model/key.rs
index ef394b7049..250f5fa32a 100644
--- a/rust/cloud-storage/document_text_extractor/src/model/key.rs
+++ b/rust/cloud-storage/document_text_extractor/src/model/key.rs
@@ -14,7 +14,7 @@ impl DocumentKeyParts {
// user_id/document_id/document_bom_id.docx
let split = key.split("/").collect::<Vec<&str>>();
if split.len() != 3 {
- return Err(anyhow::anyhow!("invalid key format"));
+ anyhow::bail!("invalid key format");
}
let encoded_user_id = split[0].to_string();
diff --git a/rust/cloud-storage/documents/src/domain/service.rs b/rust/cloud-storage/documents/src/domain/service.rs
index bce33b7235..41806b63b3 100644
--- a/rust/cloud-storage/documents/src/domain/service.rs
+++ b/rust/cloud-storage/documents/src/domain/service.rs
@@ -206,7 +206,7 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
.collect();
if shas.len() != presigned_urls.len() {
- return Err(anyhow!("unable to generate presigned urls"));
+ anyhow::bail!("unable to generate presigned urls");
}
Ok(LocationResponseData::PresignedUrls(presigned_urls))
diff --git a/rust/cloud-storage/docx_unzip_handler/src/models.rs b/rust/cloud-storage/docx_unzip_handler/src/models.rs
index 5fe2de3586..349c3f57fc 100644
--- a/rust/cloud-storage/docx_unzip_handler/src/models.rs
+++ b/rust/cloud-storage/docx_unzip_handler/src/models.rs
@@ -17,7 +17,7 @@ impl DocumentKeyParts {
// user_id/document_id/document_bom_id.docx
let split = key.split("/").collect::<Vec<&str>>();
if split.len() != 3 {
- return Err(anyhow::anyhow!("invalid key format"));
+ anyhow::bail!("invalid key format");
}
let encoded_user_id = split[0].to_string();
diff --git a/rust/cloud-storage/email_db_client/src/backfill/job/update.rs b/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
index ec34c217b1..04044cf85f 100644
--- a/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
+++ b/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
@@ -26,7 +26,7 @@ where
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
+ anyhow::bail!("No backfill job found with ID: {}", job_id);
}
Ok(())
@@ -72,7 +72,7 @@ pub async fn update_job_total_threads(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
+ anyhow::bail!("No backfill job found with ID: {}", job_id);
}
Ok(())
@@ -97,7 +97,7 @@ pub async fn update_job_threads_retrieved_count(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
+ anyhow::bail!("No backfill job found with ID: {}", job_id);
}
Ok(())
diff --git a/rust/cloud-storage/email_db_client/src/histories/mod.rs b/rust/cloud-storage/email_db_client/src/histories/mod.rs
index f314e03951..a2316a729d 100644
--- a/rust/cloud-storage/email_db_client/src/histories/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/histories/mod.rs
@@ -1,4 +1,3 @@
-use anyhow::anyhow;
use doppleganger::Mirror;
use models_email::gmail::history::{GmailHistory, GmailHistoryDb};
use sqlx::PgPool;
@@ -13,7 +12,7 @@ pub async fn fetch_history_id_for_link(
provider: models_email::service::link::UserProvider,
) -> anyhow::Result<Option<String>> {
if email_address.is_empty() {
- return Err(anyhow!("Email address cannot be empty"));
+ anyhow::bail!("Email address cannot be empty");
}
let normalized_email = email_address.to_lowercase();
diff --git a/rust/cloud-storage/email_db_client/src/labels/delete.rs b/rust/cloud-storage/email_db_client/src/labels/delete.rs
index 257e621dd7..3a7d13e57c 100644
--- a/rust/cloud-storage/email_db_client/src/labels/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/delete.rs
@@ -1,4 +1,3 @@
-use anyhow::anyhow;
use sqlx::types::Uuid;
use sqlx::{Executor, PgPool, Postgres};
@@ -19,7 +18,7 @@ where
}
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
let result = sqlx::query!(
diff --git a/rust/cloud-storage/email_db_client/src/labels/get.rs b/rust/cloud-storage/email_db_client/src/labels/get.rs
index cd64d09a79..edcf88dd7d 100644
--- a/rust/cloud-storage/email_db_client/src/labels/get.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/get.rs
@@ -1,7 +1,6 @@
#[cfg(test)]
mod test;
-use anyhow::anyhow;
use models_email::db;
use models_email::email::service::label;
use sqlx::PgPool;
@@ -17,7 +16,7 @@ pub async fn fetch_message_label(
link_id: Uuid,
) -> anyhow::Result<Option<label::MessageLabel>> {
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
let record = sqlx::query_as!(
diff --git a/rust/cloud-storage/email_db_client/src/labels/insert.rs b/rust/cloud-storage/email_db_client/src/labels/insert.rs
index 2b0c29c008..52e0b31142 100644
--- a/rust/cloud-storage/email_db_client/src/labels/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/insert.rs
@@ -1,4 +1,3 @@
-use anyhow::anyhow;
use models_email::email::{db, service};
use sqlx::types::Uuid;
use sqlx::{Executor, PgPool, Postgres};
@@ -11,7 +10,7 @@ pub async fn insert_message_label(
link_id: Uuid,
) -> anyhow::Result<()> {
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
let result = sqlx::query!(
@@ -43,11 +42,11 @@ pub async fn insert_message_label(
link_id = %link_id,
"No message label found to create relation for"
);
- Err(anyhow!(
+ anyhow::bail!(
"No label found for link_id {} with provider_label_id {}",
link_id,
provider_label_id
- ))
+ )
}
}
}
@@ -68,7 +67,7 @@ where
}
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
let result = sqlx::query!(
@@ -291,11 +290,11 @@ pub async fn insert_message_labels(
.await?;
if label_mappings.len() != provider_label_ids.len() {
- return Err(anyhow!(
+ anyhow::bail!(
"Could not find all expected labels in database after upsert. link_id: {}, provider_label_ids: {:?}",
link_id,
provider_label_ids
- ));
+ );
}
// insert into junction table
diff --git a/rust/cloud-storage/email_db_client/src/links/get.rs b/rust/cloud-storage/email_db_client/src/links/get.rs
index a21e2c4aba..f6b8eb2bda 100644
--- a/rust/cloud-storage/email_db_client/src/links/get.rs
+++ b/rust/cloud-storage/email_db_client/src/links/get.rs
@@ -1,4 +1,3 @@
-use anyhow::anyhow;
use doppleganger::Mirror;
use models_email::email::service::link;
use models_email::service;
@@ -15,7 +14,7 @@ pub async fn fetch_link_by_email(
provider: service::link::UserProvider,
) -> anyhow::Result<Option<link::Link>> {
if email_address.is_empty() {
- return Err(anyhow!("Email address cannot be empty"));
+ anyhow::bail!("Email address cannot be empty");
}
let db_link = sqlx::query_as!(
@@ -43,7 +42,7 @@ pub async fn fetch_link_by_macro_id(
macro_id: &str,
) -> anyhow::Result<Option<link::Link>> {
if macro_id.is_empty() {
- return Err(anyhow!("Macro ID cannot be empty"));
+ anyhow::bail!("Macro ID cannot be empty");
}
let db_link = sqlx::query_as!(
@@ -72,7 +71,7 @@ pub async fn fetch_links_by_fusionauth_user_id(
fusionauth_user_id: &str,
) -> anyhow::Result<Vec<link::Link>> {
if fusionauth_user_id.is_empty() {
- return Err(anyhow!("fusionauth_user_id cannot be empty"));
+ anyhow::bail!("fusionauth_user_id cannot be empty");
}
let db_links = sqlx::query_as!(
diff --git a/rust/cloud-storage/email_db_client/src/links/insert.rs b/rust/cloud-storage/email_db_client/src/links/insert.rs
index ed35930cea..81c2efd1a9 100644
--- a/rust/cloud-storage/email_db_client/src/links/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/links/insert.rs
@@ -1,4 +1,3 @@
-use anyhow::anyhow;
use doppleganger::Mirror;
use models_email::email::service;
use sqlx::PgPool;
@@ -20,7 +19,7 @@ pub async fn upsert_link(
service_link: service::link::Link,
) -> anyhow::Result<service::link::Link> {
if service_link.fusionauth_user_id.is_empty() {
- return Err(anyhow!("FusionAuth User ID cannot be empty"));
+ anyhow::bail!("FusionAuth User ID cannot be empty");
}
let service::link::Link {
diff --git a/rust/cloud-storage/email_db_client/src/messages/delete.rs b/rust/cloud-storage/email_db_client/src/messages/delete.rs
index c0e58da242..733e553c2f 100644
--- a/rust/cloud-storage/email_db_client/src/messages/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/delete.rs
@@ -43,7 +43,7 @@ where
// Check if any rows were affected
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("Message not found with id {}", message_id));
+ anyhow::bail!("Message not found with id {}", message_id);
}
Ok(())
diff --git a/rust/cloud-storage/email_db_client/src/threads/get.rs b/rust/cloud-storage/email_db_client/src/threads/get.rs
index 1c5ccbc37e..b26c2f02cd 100644
--- a/rust/cloud-storage/email_db_client/src/threads/get.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/get.rs
@@ -1,5 +1,4 @@
use crate::parse::db_to_service;
-use anyhow::anyhow;
use models_email::email::service::thread::{
ThreadProviderMap, ThreadUserInfo, UserThreadIds, UserThreadsPage,
};
@@ -42,9 +41,7 @@ pub async fn get_latest_thread_ids_paginated(
offset: i64,
) -> anyhow::Result<Vec<Uuid>> {
if offset < 0 || limit <= 0 {
- return Err(anyhow!(
- "Offset must be non-negative and limit must be positive"
- ));
+ anyhow::bail!("Offset must be non-negative and limit must be positive");
}
let thread_ids = sqlx::query_scalar!(
diff --git a/rust/cloud-storage/email_db_client/src/threads/insert.rs b/rust/cloud-storage/email_db_client/src/threads/insert.rs
index 6df7219792..b2e1488e9e 100644
--- a/rust/cloud-storage/email_db_client/src/threads/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/insert.rs
@@ -78,11 +78,11 @@ pub async fn insert_thread_and_messages(
if let Err(err) = result {
if let Err(rollback_err) = tx.rollback().await {
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Transaction failed: {} AND rollback also failed: {}",
err,
rollback_err
- ));
+ );
}
return Err(err);
}
diff --git a/rust/cloud-storage/email_service/src/api/email/messages/labels.rs b/rust/cloud-storage/email_service/src/api/email/messages/labels.rs
index fe6127ed9e..7286bc6a69 100644
--- a/rust/cloud-storage/email_service/src/api/email/messages/labels.rs
+++ b/rust/cloud-storage/email_service/src/api/email/messages/labels.rs
@@ -1,6 +1,5 @@
use crate::api::context::ApiContext;
use crate::api::email::messages::BATCH_UPDATE_MESSAGE_LIMIT;
-use anyhow::anyhow;
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
@@ -226,7 +225,7 @@ pub async fn add_label_to_messages(
}
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
// First clone for the Gmail API operations
@@ -334,7 +333,7 @@ pub async fn remove_label_from_messages(
}
if provider_label_id.is_empty() {
- return Err(anyhow!("Provider label ID cannot be empty"));
+ anyhow::bail!("Provider label ID cannot be empty");
}
// First clone for the Gmail API operations
diff --git a/rust/cloud-storage/email_service/src/util/process_pre_insert/sfs_map.rs b/rust/cloud-storage/email_service/src/util/process_pre_insert/sfs_map.rs
index 00fb4f6f37..86b9d6e78a 100644
--- a/rust/cloud-storage/email_service/src/util/process_pre_insert/sfs_map.rs
+++ b/rust/cloud-storage/email_service/src/util/process_pre_insert/sfs_map.rs
@@ -222,23 +222,23 @@ async fn fetch_image(original_url_str: &str) -> anyhow::Result<Option<Bytes>> {
Err(e) => {
let error_chain = build_error_chain(&e);
if e.is_timeout() {
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Timeout fetching URL: {} - Full error: {}",
original_url_str,
error_chain
- ));
+ );
} else if e.is_connect() {
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Connection error for URL: {} - Full error: {}",
original_url_str,
error_chain
- ));
+ );
}
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Network error fetching URL: {} - Full error: {}",
original_url_str,
error_chain
- ));
+ );
}
};
diff --git a/rust/cloud-storage/email_service/src/utils.rs b/rust/cloud-storage/email_service/src/utils.rs
index e8af10e641..192e0bea3d 100644
--- a/rust/cloud-storage/email_service/src/utils.rs
+++ b/rust/cloud-storage/email_service/src/utils.rs
@@ -12,7 +12,7 @@ pub fn email_from_user_id(user_id: &str) -> anyhow::Result<String> {
.ok_or_else(|| anyhow::anyhow!("invalid user id format"))?;
if email.is_empty() {
- return Err(anyhow::anyhow!("empty email in user id"));
+ anyhow::bail!("empty email in user id");
}
Ok(email)
diff --git a/rust/cloud-storage/gmail_client/src/attachments.rs b/rust/cloud-storage/gmail_client/src/attachments.rs
index 9084a930f0..02ff249587 100644
--- a/rust/cloud-storage/gmail_client/src/attachments.rs
+++ b/rust/cloud-storage/gmail_client/src/attachments.rs
@@ -31,11 +31,11 @@ pub async fn get_attachment_data(
.await
.context("Failed to get response body")?;
if !status.is_success() {
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Gmail API returned an error status: {} (get attachment): {}",
status,
body_text
- ));
+ );
}
let attachment_response: AttachmentGetResponse = serde_json::from_str(&body_text)
diff --git a/rust/cloud-storage/gmail_client/src/auth.rs b/rust/cloud-storage/gmail_client/src/auth.rs
index 859e3e6629..3a94e03a7b 100644
--- a/rust/cloud-storage/gmail_client/src/auth.rs
+++ b/rust/cloud-storage/gmail_client/src/auth.rs
@@ -48,9 +48,7 @@ pub(crate) async fn fetch_google_public_keys(
}
if keys_map.is_empty() {
- return Err(anyhow::anyhow!(
- "No valid RSA keys found in Google JWKS response"
- ));
+ anyhow::bail!("No valid RSA keys found in Google JWKS response");
}
Ok(GooglePublicKeys {
diff --git a/rust/cloud-storage/gmail_client/src/messages.rs b/rust/cloud-storage/gmail_client/src/messages.rs
index b8fd0b05db..f1e803bde3 100644
--- a/rust/cloud-storage/gmail_client/src/messages.rs
+++ b/rust/cloud-storage/gmail_client/src/messages.rs
@@ -216,11 +216,11 @@ pub(crate) async fn send_message(
.await
.context("Failed to get response body")?;
if !status.is_success() {
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"Gmail API returned an error status: {} (send message): {}",
status,
body_text
- ));
+ );
}
let message_response: SentMessageResource = serde_json::from_str(&body_text)
diff --git a/rust/cloud-storage/gmail_client/src/threads.rs b/rust/cloud-storage/gmail_client/src/threads.rs
index 469e32e87d..6f2d3cdbe8 100644
--- a/rust/cloud-storage/gmail_client/src/threads.rs
+++ b/rust/cloud-storage/gmail_client/src/threads.rs
@@ -104,8 +104,7 @@ pub async fn get_threads_with_retry(
last_error = Some(RateLimitExceeded); // Store the error type
if attempt == MAX_RETRY_ATTEMPTS - 1 {
// Return the specific error wrapped in anyhow with additional context
- return Err(anyhow!(RateLimitExceeded)
- .context(format!("thread_ids: {:?}", thread_ids)));
+ anyhow::bail!(RateLimitExceeded);
}
// Reduce batch size for next attempt
@@ -123,9 +122,7 @@ pub async fn get_threads_with_retry(
current_delay *= 2;
}
other_error => {
- return Err(
- anyhow!(other_error).context(format!("thread_ids: {:?}", thread_ids))
- );
+ anyhow::bail!(other_error);
}
}
}
diff --git a/rust/cloud-storage/lambda_client/src/invoke.rs b/rust/cloud-storage/lambda_client/src/invoke.rs
index bf90d09809..3909400b5a 100644
--- a/rust/cloud-storage/lambda_client/src/invoke.rs
+++ b/rust/cloud-storage/lambda_client/src/invoke.rs
@@ -29,10 +29,10 @@ where
"lambda invocation failed with status code {}",
response.status_code()
);
- return Err(anyhow::anyhow!(
+ anyhow::bail!(
"lambda invocation failed with status code {}",
response.status_code()
- ));
+ );
}
Ok(())
diff --git a/rust/cloud-storage/lexical_client/src/parse_markdown.rs b/rust/cloud-storage/lexical_client/src/parse_markdown.rs
index 239ede3a2b..3dfa4c0c8a 100644
--- a/rust/cloud-storage/lexical_client/src/parse_markdown.rs
+++ b/rust/cloud-storage/lexical_client/src/parse_markdown.rs
@@ -41,7 +41,7 @@ impl LexicalClient {
status=%status_code,
"unexpected response from sync service while getting raw document"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
let data: LexicalResponse = response.json().await?;
@@ -65,7 +65,7 @@ impl LexicalClient {
status=%status_code,
"unexpected response from sync service while getting raw document"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
response
diff --git a/rust/cloud-storage/macro_db_client/src/annotations/create_anchor.rs b/rust/cloud-storage/macro_db_client/src/annotations/create_anchor.rs
index e359008622..baa1879ffb 100644
--- a/rust/cloud-storage/macro_db_client/src/annotations/create_anchor.rs
+++ b/rust/cloud-storage/macro_db_client/src/annotations/create_anchor.rs
@@ -17,7 +17,7 @@ use super::AnchorTableName;
fn _validate_thread_ids(thread_id: i64, anchor_thread_id: Option<i64>) -> Result<()> {
let incompatible_thread_ids = anchor_thread_id.is_some_and(|id| id != thread_id);
if incompatible_thread_ids {
- return Err(anyhow::anyhow!("provided thread ids do not match"));
+ anyhow::bail!("provided thread ids do not match");
}
Ok(())
}
diff --git a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs b/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
index 0adcb7e089..e38bdbae48 100644
--- a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
@@ -163,7 +163,7 @@ pub(in crate::document) async fn copy_non_docx_document(
Some(sha) => sha.as_str(),
None => {
tracing::error!("unable to copy pdf document, sha is missing");
- return Err(anyhow::Error::msg("unable to copy document"));
+ anyhow::bail!("unable to copy document");
}
};
diff --git a/rust/cloud-storage/macro_db_client/src/document/create_blank_docx.rs b/rust/cloud-storage/macro_db_client/src/document/create_blank_docx.rs
index ebc8d61c88..8ed4f40b41 100644
--- a/rust/cloud-storage/macro_db_client/src/document/create_blank_docx.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/create_blank_docx.rs
@@ -137,7 +137,7 @@ pub async fn create_blank_docx(
document_id=?document.id,
"transaction error",
);
- return Err(anyhow::Error::msg("unable to create blank docx document"));
+ anyhow::bail!("unable to create blank docx document");
}
let parts_json: serde_json::Value = serde_json::to_value(document_bom_parts)?;
diff --git a/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs b/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
index 7d039867b7..8a96b63b14 100644
--- a/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
@@ -65,9 +65,7 @@ pub async fn create_onboarding_documents(
.iter()
.any(|(_, file_type)| file_type == FileType::Docx.as_str())
{
- return Err(anyhow::Error::msg(
- "docx is not supported for onboarding documents",
- ));
+ anyhow::bail!("docx is not supported for onboarding documents");
}
let document_values = document_names
diff --git a/rust/cloud-storage/macro_db_client/src/document/save_document.rs b/rust/cloud-storage/macro_db_client/src/document/save_document.rs
index e38802c391..edb19e5968 100644
--- a/rust/cloud-storage/macro_db_client/src/document/save_document.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/save_document.rs
@@ -133,7 +133,7 @@ DELETE FROM "PdfHighlightAnchor" WHERE "documentId" = $1;
let parsed_uuid_result = Uuid::try_parse(thread.head_id.as_str());
if let Err(_e) = parsed_uuid_result {
tracing::error!("head id is not a valid uuid");
- return Err(anyhow::anyhow!("head id is not a valid uuid"));
+ anyhow::bail!("head id is not a valid uuid");
}
let _pdf_anchor_id = sqlx::query_scalar!(
@@ -271,7 +271,7 @@ DELETE FROM "PdfHighlightAnchor" WHERE "documentId" = $1;
let highlight_anchor_uuid =
if let Some(highlight_uuid) = highlight.uuid.as_deref().map(Uuid::try_parse) {
if let Err(_e) = highlight_uuid {
- return Err(anyhow::anyhow!("invalid highlight uuid"));
+ anyhow::bail!("invalid highlight uuid");
}
let highlight_uuid = highlight_uuid.unwrap();
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
index f7decd7f00..1a1016cc15 100644
--- a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
@@ -132,9 +132,7 @@ pub async fn create_document_txn(
let sub_type: Option<DocumentSubType> = if is_task {
if file_type != Some(FileType::Md) {
- return Err(anyhow::anyhow!(
- "is_task is only applicable for md documents"
- ));
+ anyhow::bail!("is_task is only applicable for md documents");
}
sqlx::query!(
@@ -311,15 +309,12 @@ async fn insert_document_with_id(
&& db_err.is_unique_violation()
{
tracing::warn!(error=?err, "document with ID already exists");
- return Err(anyhow::anyhow!("document with ID already exists: {}", id));
+ anyhow::bail!("document with ID already exists: {}", id);
}
// All other errors
tracing::error!(error=?err, "unable to create document with specified ID");
- Err(anyhow::anyhow!(
- "unable to create document with specified ID: {}",
- err
- ))
+ anyhow::bail!("unable to create document with specified ID: {}", err)
}
}
}
diff --git a/rust/cloud-storage/macro_db_client/src/job/upload_job.rs b/rust/cloud-storage/macro_db_client/src/job/upload_job.rs
index 37e5a92d8d..3a67ef138e 100644
--- a/rust/cloud-storage/macro_db_client/src/job/upload_job.rs
+++ b/rust/cloud-storage/macro_db_client/src/job/upload_job.rs
@@ -17,7 +17,7 @@ pub async fn update_upload_job(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("jobId not found"));
+ anyhow::bail!("jobId not found");
}
Ok(())
diff --git a/rust/cloud-storage/macro_db_client/src/projects/move_item.rs b/rust/cloud-storage/macro_db_client/src/projects/move_item.rs
index ef564ef1ce..8377e976a8 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/move_item.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/move_item.rs
@@ -42,7 +42,7 @@ pub async fn move_item_to_project(
.await?;
}
_ => {
- return Err(anyhow::anyhow!("Invalid item type"));
+ anyhow::bail!("Invalid item type");
}
}
diff --git a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
index 4ad92c095a..28c604e3fa 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
@@ -240,7 +240,7 @@ pub async fn mark_projects_uploaded(
let project_ids = get_all_sub_project_ids(&mut transaction, root_project_id).await?;
if project_ids.is_empty() {
- return Err(anyhow::anyhow!("Project not found: {}", root_project_id));
+ anyhow::bail!("Project not found: {}", root_project_id);
}
// Update all projects to set uploadPending to false
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
index 818e5a4c03..89d9b1c6d7 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
@@ -81,9 +81,7 @@ pub async fn get_share_permission_id(
.id
}
_ => {
- return Err(anyhow::anyhow!(format!(
- "unsupported item type {item_type}"
- )));
+ anyhow::bail!("unsupported item type {item_type}");
}
};
diff --git a/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs b/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
index fc0a412192..d771654017 100644
--- a/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/patch/mod.rs
@@ -65,7 +65,7 @@ pub async fn patch_user_group(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("user not found"));
+ anyhow::bail!("user not found");
}
Ok(())
@@ -90,7 +90,7 @@ pub async fn patch_user_tutorial(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("user not found"));
+ anyhow::bail!("user not found");
}
Ok(())
@@ -155,7 +155,7 @@ pub async fn patch_user_onboarding(
.await?;
if result.rows_affected() == 0 {
- return Err(anyhow::anyhow!("user not found"));
+ anyhow::bail!("user not found");
}
Ok(())
diff --git a/rust/cloud-storage/macro_uuid/src/lib.rs b/rust/cloud-storage/macro_uuid/src/lib.rs
index 2d89958588..1d9eb1fd94 100644
--- a/rust/cloud-storage/macro_uuid/src/lib.rs
+++ b/rust/cloud-storage/macro_uuid/src/lib.rs
@@ -61,7 +61,7 @@ impl ShortUuidConverter {
/// converts short uuid to uuid
pub fn to_uuid(&self, short_uuid: &str) -> Result<Uuid> {
if !self.is_short_uuid(short_uuid) {
- return Err(anyhow!("Invalid short UUID format"));
+ anyhow::bail!("Invalid short UUID format");
}
// Convert from base58 to number
diff --git a/rust/cloud-storage/model/src/document/response/mod.rs b/rust/cloud-storage/model/src/document/response/mod.rs
index 8ac2747633..5a9d678f84 100644
--- a/rust/cloud-storage/model/src/document/response/mod.rs
+++ b/rust/cloud-storage/model/src/document/response/mod.rs
@@ -162,9 +162,7 @@ impl DocumentResponseMetadata {
let document_bom: Vec<BomPart> = match serde_json::from_value(document_bom.clone()) {
Ok(document_bom) => document_bom,
Err(e) => {
- return Err(anyhow::anyhow!(format!(
- "document bom could not be serialized {e}",
- )));
+ anyhow::bail!("document bom could not be serialized {e}");
}
};
document_response_metadata.document_bom = Some(document_bom);
diff --git a/rust/cloud-storage/model/src/folder.rs b/rust/cloud-storage/model/src/folder.rs
index 4eab3b2fda..72495ebe45 100644
--- a/rust/cloud-storage/model/src/folder.rs
+++ b/rust/cloud-storage/model/src/folder.rs
@@ -81,7 +81,7 @@ impl FileSystemNode {
pub fn get_root_folder(&self, root_folder_name: &str) -> anyhow::Result<&FileSystemNode> {
let item = match self {
FileSystemNode::File(_) => {
- return Err(anyhow::anyhow!("Expected a folder node, found a file"));
+ anyhow::bail!("Expected a folder node, found a file");
}
FileSystemNode::Folder(folder) => folder,
};
@@ -130,7 +130,7 @@ impl FileSystemNode {
fn as_folder_mut(&mut self) -> anyhow::Result<&mut HashMap<String, FileSystemNode>> {
match self {
FileSystemNode::Folder(folder) => Ok(folder),
- _ => Err(anyhow::anyhow!("Expected a folder node, found a file")),
+ _ => anyhow::bail!("Expected a folder node, found a file"),
}
}
}
diff --git a/rust/cloud-storage/opensearch_client/src/lib.rs b/rust/cloud-storage/opensearch_client/src/lib.rs
index 6a28f140ed..3cefb9711e 100644
--- a/rust/cloud-storage/opensearch_client/src/lib.rs
+++ b/rust/cloud-storage/opensearch_client/src/lib.rs
@@ -62,9 +62,7 @@ impl OpensearchClient {
let status = response.status_code();
if status != 200 {
- return Err(anyhow::anyhow!(
- "Health check failed with status code {status}"
- ));
+ anyhow::bail!("Health check failed with status code {status}");
}
Ok(())
@@ -102,7 +100,7 @@ impl OpensearchClient {
.await?;
if !response.status_code().is_success() {
- return Err(anyhow::anyhow!("error creating index: {response:?}"));
+ anyhow::bail!("error creating index: {response:?}");
}
}
diff --git a/rust/cloud-storage/search_upload_handler/src/handler.rs b/rust/cloud-storage/search_upload_handler/src/handler.rs
index 8cb08d204f..9d49693464 100644
--- a/rust/cloud-storage/search_upload_handler/src/handler.rs
+++ b/rust/cloud-storage/search_upload_handler/src/handler.rs
@@ -26,13 +26,13 @@ impl TryFrom<String> for DocumentKeyParts {
let parts: Vec<&str> = value.split('/').collect();
if parts.len() != 3 {
- return Err(anyhow::anyhow!("expected 3 parts, got {}", parts.len()));
+ anyhow::bail!("expected 3 parts, got {}", parts.len());
}
let file: Vec<&str> = parts[2].split('.').collect::<Vec<&str>>();
if file.len() != 2 {
- return Err(anyhow::anyhow!("expected 2 file parts, got {}", file.len()));
+ anyhow::bail!("expected 2 file parts, got {}", file.len());
}
Ok(Self {
diff --git a/rust/cloud-storage/sqs_worker/src/lib.rs b/rust/cloud-storage/sqs_worker/src/lib.rs
index c0811cbbad..ebc45cdc7f 100644
--- a/rust/cloud-storage/sqs_worker/src/lib.rs
+++ b/rust/cloud-storage/sqs_worker/src/lib.rs
@@ -47,7 +47,7 @@ impl SQSWorker {
delete_message::delete_message(&self.inner, &self.queue_url, receipt_handle).await?;
} else {
tracing::warn!("no receipt handle found for message");
- return Err(anyhow::anyhow!("no receipt handle found for message"));
+ anyhow::bail!("no receipt handle found for message");
}
Ok(())
}
diff --git a/rust/cloud-storage/static_file_service_client/src/get_file.rs b/rust/cloud-storage/static_file_service_client/src/get_file.rs
index 0ecbd4c0bf..c7ff70d5e6 100644
--- a/rust/cloud-storage/static_file_service_client/src/get_file.rs
+++ b/rust/cloud-storage/static_file_service_client/src/get_file.rs
@@ -14,7 +14,7 @@ impl StaticFileServiceClient {
let status_code = response.status();
if status_code == reqwest::StatusCode::NOT_FOUND {
- return Err(anyhow::anyhow!("File not found: {}", file_id));
+ anyhow::bail!("File not found: {}", file_id);
}
if !status_code.is_success() {
@@ -24,7 +24,7 @@ impl StaticFileServiceClient {
status=%status_code,
"unexpected response from static file service"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let file_bytes = response.bytes().await?;
@@ -51,7 +51,7 @@ impl StaticFileServiceClient {
status=%status_code,
"unexpected response from static file service"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let metadata: FileMetadata = response.json().await?;
@@ -68,7 +68,7 @@ impl StaticFileServiceClient {
let status_code = response.status();
if status_code == reqwest::StatusCode::NOT_FOUND {
- return Err(anyhow::anyhow!("File not found: {}", file_id));
+ anyhow::bail!("File not found: {}", file_id);
}
if !status_code.is_success() {
@@ -78,7 +78,7 @@ impl StaticFileServiceClient {
status=%status_code,
"unexpected response from static file service"
);
- return Err(anyhow::anyhow!("HTTP {}: {}", status_code, body));
+ anyhow::bail!("HTTP {}: {}", status_code, body);
}
let presigned_url = response.text().await?;
diff --git a/rust/cloud-storage/static_file_service_client/src/put_file.rs b/rust/cloud-storage/static_file_service_client/src/put_file.rs
index 2a4391926d..71dc24de02 100644
--- a/rust/cloud-storage/static_file_service_client/src/put_file.rs
+++ b/rust/cloud-storage/static_file_service_client/src/put_file.rs
@@ -1,5 +1,5 @@
use super::StaticFileServiceClient;
-use anyhow::{Context, Result, anyhow};
+use anyhow::{Context, Result};
use bytes::Bytes;
use reqwest::header::CONTENT_TYPE;
use serde::{Deserialize, Serialize};
@@ -69,7 +69,7 @@ impl StaticFileServiceClient {
status=%status_code,
"unexpected response from document storage service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
let res = res.json().await?;
@@ -87,7 +87,7 @@ impl StaticFileServiceClient {
.await?;
if !upload_response.status().is_success() {
- return Err(anyhow!("Upload failed: {}", upload_response.status()));
+ anyhow::bail!("Upload failed: {}", upload_response.status());
}
Ok(put_file_data)
diff --git a/rust/cloud-storage/sync_service_client/src/copy_document.rs b/rust/cloud-storage/sync_service_client/src/copy_document.rs
index 83081de224..f88177e898 100644
--- a/rust/cloud-storage/sync_service_client/src/copy_document.rs
+++ b/rust/cloud-storage/sync_service_client/src/copy_document.rs
@@ -38,7 +38,7 @@ impl SyncServiceClient {
status=%status_code,
"unexpected response from sync service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
Ok(())
diff --git a/rust/cloud-storage/sync_service_client/src/delete.rs b/rust/cloud-storage/sync_service_client/src/delete.rs
index 065918a419..f10af9d840 100644
--- a/rust/cloud-storage/sync_service_client/src/delete.rs
+++ b/rust/cloud-storage/sync_service_client/src/delete.rs
@@ -15,7 +15,7 @@ impl SyncServiceClient {
status=%status_code,
"could not delete document from sync service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
Ok(())
diff --git a/rust/cloud-storage/sync_service_client/src/get_raw.rs b/rust/cloud-storage/sync_service_client/src/get_raw.rs
index 557beb77ed..56e0b86502 100644
--- a/rust/cloud-storage/sync_service_client/src/get_raw.rs
+++ b/rust/cloud-storage/sync_service_client/src/get_raw.rs
@@ -15,7 +15,7 @@ impl SyncServiceClient {
status=%status_code,
"unexpected response from sync service while getting raw document"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
let raw = res.text().await?;
diff --git a/rust/cloud-storage/sync_service_client/src/metadata.rs b/rust/cloud-storage/sync_service_client/src/metadata.rs
index 7aa0b21bb3..c67f768d07 100644
--- a/rust/cloud-storage/sync_service_client/src/metadata.rs
+++ b/rust/cloud-storage/sync_service_client/src/metadata.rs
@@ -18,7 +18,7 @@ impl SyncServiceClient {
status=%status_code,
"unexpected response from sync service"
);
- return Err(anyhow::anyhow!(body));
+ anyhow::bail!(body);
}
let metadata: DocumentMetadata = res.json().await?;
diff --git a/rust/cloud-storage/target/lambda/search_upload_handler/bootstrap.zip b/rust/cloud-storage/target/lambda/search_upload_handler/bootstrap.zip
index 68da004aa5..ef3569b213 100644
Binary files a/rust/cloud-storage/target/lambda/search_upload_handler/bootstrap.zip and b/rust/cloud-storage/target/lambda/search_upload_handler/bootstrap.zip differ