From def1d6afda1bb0342c685503acabb3cf7e9a7687 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 30 Aug 2025 16:44:28 -0400 Subject: [PATCH] errors for object gen --- .../core/commands/enqueue/generate_error.rs | 6 +- .../enqueue_image_bg_removal_command.rs | 2 +- .../handle_generic_bg_removal_artcraft.rs | 2 +- .../enqueue_image_to_3d_object_command.rs | 12 ++-- .../image_to_object/generic/handle_object.rs | 6 +- .../generic/handle_object_artcraft.rs | 12 ++-- .../generic/handle_object_fal.rs | 16 ++--- .../image_to_object/internal_object_error.rs | 62 ------------------- .../commands/enqueue/image_to_object/mod.rs | 1 - .../generic/handle_video_fal.rs | 2 +- 10 files changed, 31 insertions(+), 90 deletions(-) delete mode 100644 crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/internal_object_error.rs diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/generate_error.rs b/crates/desktop/artcraft/src/core/commands/enqueue/generate_error.rs index 050c574de6..810c8f7b01 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/generate_error.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/generate_error.rs @@ -31,7 +31,7 @@ pub enum GenerateError { pub enum BadInputReason { NoModelSpecified, /// An image was required but not provided. - ImageMissing, + NoImageSpecified, Base64DecodeError, } @@ -74,6 +74,10 @@ impl GenerateError { // Bad input // + pub fn no_image_specified() -> Self { + Self::BadInput(BadInputReason::NoImageSpecified) + } + pub fn no_model_specified() -> Self { Self::BadInput(BadInputReason::NoModelSpecified) } diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs index 709e1359b6..7ee7fdfa71 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs @@ -208,7 +208,7 @@ fn error_to_tauri_response(error: GenerateError) -> CommandErrorResponseWrapper< error_type = EnqueueImageBgRemovalErrorType::NoProviderAvailable; error_message = "No configured provider available for background removal".to_string(); } - GenerateError::BadInput(BadInputReason::ImageMissing) => { + GenerateError::BadInput(BadInputReason::NoImageSpecified) => { status = CommandErrorStatus::BadRequest; error_type = EnqueueImageBgRemovalErrorType::MissingImage; error_message = "No image provided for background removal".to_string(); diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/generic/handle_generic_bg_removal_artcraft.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/generic/handle_generic_bg_removal_artcraft.rs index 7fac603b3c..ec041e6af6 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/generic/handle_generic_bg_removal_artcraft.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/generic/handle_generic_bg_removal_artcraft.rs @@ -113,7 +113,7 @@ async fn upload_image_from_base64_bytes( GenerateError::BadInput(BadInputReason::Base64DecodeError) })?; } else { - return Err(GenerateError::BadInput(BadInputReason::ImageMissing)); + return Err(GenerateError::BadInput(BadInputReason::NoImageSpecified)); }; info!("Uploading image media file from temp file: {:?}", temp_file.path()); diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/enqueue_image_to_3d_object_command.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/enqueue_image_to_3d_object_command.rs index 881575303d..a2d12cb69b 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/enqueue_image_to_3d_object_command.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/enqueue_image_to_3d_object_command.rs @@ -1,5 +1,5 @@ +use crate::core::commands::enqueue::generate_error::{BadInputReason, GenerateError, MissingCredentialsReason}; use crate::core::commands::enqueue::image_to_object::generic::handle_object::handle_object; -use crate::core::commands::enqueue::image_to_object::internal_object_error::InternalObjectError; use crate::core::commands::enqueue::task_enqueue_success::TaskEnqueueSuccess; use crate::core::commands::response::failure_response_wrapper::{CommandErrorResponseWrapper, CommandErrorStatus}; use crate::core::commands::response::shorthand::Response; @@ -102,22 +102,22 @@ pub async fn enqueue_image_to_3d_object_command( let mut error_message = "A server error occurred. Please try again. If it continues, please tell our staff about the problem."; match err { - InternalObjectError::NoModelSpecified => { + GenerateError::BadInput(BadInputReason::NoModelSpecified) => { status = CommandErrorStatus::BadRequest; error_type = EnqueueImageTo3dObjectErrorType::ModelNotSpecified; error_message = "No model specified for object generation"; } - InternalObjectError::NoProviderAvailable => { + GenerateError::NoProviderAvailable => { status = CommandErrorStatus::ServerError; error_type = EnqueueImageTo3dObjectErrorType::NoProviderAvailable; error_message = "No configured provider available for object generation"; } - InternalObjectError::NeedsFalApiKey => { + GenerateError::MissingCredentials(MissingCredentialsReason::NeedsFalApiKey) => { status = CommandErrorStatus::Unauthorized; error_type = EnqueueImageTo3dObjectErrorType::NeedsFalApiKey; error_message = "You need to set a FAL api key"; }, - InternalObjectError::NeedsStorytellerCredentials => { + GenerateError::MissingCredentials(MissingCredentialsReason::NeedsStorytellerCredentials) => { status = CommandErrorStatus::Unauthorized; error_type = EnqueueImageTo3dObjectErrorType::NeedsStorytellerCredentials; error_message = "You need to be logged into Artcraft."; @@ -159,7 +159,7 @@ pub async fn handle_request( fal_creds_manager: &FalCredentialManager, storyteller_creds_manager: &StorytellerCredentialManager, fal_task_queue: &FalTaskQueue, -) -> Result { +) -> Result { let result = handle_object( request, diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object.rs index 5f82d60f8a..c9d195f3d8 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object.rs @@ -1,7 +1,6 @@ use crate::core::commands::enqueue::image_to_object::enqueue_image_to_3d_object_command::EnqueueImageTo3dObjectRequest; use crate::core::commands::enqueue::image_to_object::generic::handle_object_artcraft::handle_object_artcraft; use crate::core::commands::enqueue::image_to_object::generic::handle_object_fal::handle_object_fal; -use crate::core::commands::enqueue::image_to_object::internal_object_error::InternalObjectError; use crate::core::commands::enqueue::task_enqueue_success::TaskEnqueueSuccess; use crate::core::state::app_env_configs::app_env_configs::AppEnvConfigs; use crate::core::state::data_dir::app_data_root::AppDataRoot; @@ -10,6 +9,7 @@ use crate::services::fal::state::fal_credential_manager::FalCredentialManager; use crate::services::fal::state::fal_task_queue::FalTaskQueue; use crate::services::storyteller::state::storyteller_credential_manager::StorytellerCredentialManager; use tauri::AppHandle; +use crate::core::commands::enqueue::generate_error::GenerateError; pub async fn handle_object( request: EnqueueImageTo3dObjectRequest, @@ -20,7 +20,7 @@ pub async fn handle_object( fal_creds_manager: &FalCredentialManager, storyteller_creds_manager: &StorytellerCredentialManager, fal_task_queue: &FalTaskQueue, -) -> Result { +) -> Result { let priority = provider_priority_store.get_priority()?; @@ -51,5 +51,5 @@ pub async fn handle_object( } } - Err(InternalObjectError::NoProviderAvailable) + Err(GenerateError::NoProviderAvailable) } diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_artcraft.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_artcraft.rs index 2e746991e2..97518d5013 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_artcraft.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_artcraft.rs @@ -1,5 +1,5 @@ +use crate::core::commands::enqueue::generate_error::GenerateError; use crate::core::commands::enqueue::image_to_object::enqueue_image_to_3d_object_command::{EnqueueImageTo3dObjectModel, EnqueueImageTo3dObjectRequest}; -use crate::core::commands::enqueue::image_to_object::internal_object_error::InternalObjectError; use crate::core::commands::enqueue::task_enqueue_success::TaskEnqueueSuccess; use crate::core::events::basic_sendable_event_trait::BasicSendableEvent; use crate::core::events::generation_events::common::{GenerationAction, GenerationModel, GenerationServiceProvider}; @@ -25,7 +25,7 @@ pub async fn handle_object_artcraft( app_env_configs: &AppEnvConfigs, app_data_root: &AppDataRoot, storyteller_creds_manager: &StorytellerCredentialManager, -) -> Result { +) -> Result { let creds = match storyteller_creds_manager.get_credentials()? { Some(creds) => creds, @@ -38,7 +38,7 @@ pub async fn handle_object_artcraft( error!("Failed to emit event: {:?}", err); // Fail open. } - return Err(InternalObjectError::NeedsStorytellerCredentials); + return Err(GenerateError::needs_storyteller_credentials()); }, }; @@ -50,7 +50,7 @@ pub async fn handle_object_artcraft( let job_token = match request.model { None => { - return Err(InternalObjectError::NoModelSpecified); + return Err(GenerateError::no_model_specified()); } Some( EnqueueImageTo3dObjectModel::Hunyuan3d2 | @@ -74,7 +74,7 @@ pub async fn handle_object_artcraft( } Err(err) => { error!("Failed to use Artcraft Hunyuan 3D 2.0: {:?}", err); - return Err(InternalObjectError::StorytellerError(err)); + return Err(GenerateError::from(err)); } } } @@ -97,7 +97,7 @@ pub async fn handle_object_artcraft( } Err(err) => { error!("Failed to use Artcraft Hunyuan 3D 2.1: {:?}", err); - return Err(InternalObjectError::StorytellerError(err)); + return Err(GenerateError::from(err)); } } } diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_fal.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_fal.rs index 7a7ccfa1c5..c3cfa10b5e 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_fal.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/generic/handle_object_fal.rs @@ -1,5 +1,5 @@ +use crate::core::commands::enqueue::generate_error::GenerateError; use crate::core::commands::enqueue::image_to_object::enqueue_image_to_3d_object_command::{EnqueueImageTo3dObjectModel, EnqueueImageTo3dObjectRequest}; -use crate::core::commands::enqueue::image_to_object::internal_object_error::InternalObjectError; use crate::core::commands::enqueue::task_enqueue_success::TaskEnqueueSuccess; use crate::core::events::basic_sendable_event_trait::BasicSendableEvent; use crate::core::events::generation_events::common::{GenerationAction, GenerationModel, GenerationServiceProvider}; @@ -25,7 +25,7 @@ pub async fn handle_object_fal( request: EnqueueImageTo3dObjectRequest, fal_creds_manager: &FalCredentialManager, fal_task_queue: &FalTaskQueue, -) -> Result { +) -> Result { let api_key = match fal_creds_manager.get_key()? { Some(key) => key, @@ -38,7 +38,7 @@ pub async fn handle_object_fal( error!("Failed to emit event: {:?}", err); // Fail open. } - return Err(InternalObjectError::NeedsFalApiKey); + return Err(GenerateError::needs_fal_api_key()); }, }; @@ -57,7 +57,7 @@ pub async fn handle_object_fal( &media_token ).await?; } else { - return Err(InternalObjectError::AnyhowError(anyhow!("No image media token provided"))); + return Err(GenerateError::no_image_specified()); } info!("Calling FAL image to 3d ..."); @@ -68,7 +68,7 @@ pub async fn handle_object_fal( let result = match request.model { None => { - return Err(InternalObjectError::NoModelSpecified); + return Err(GenerateError::no_model_specified()); } Some( EnqueueImageTo3dObjectModel::Hunyuan3d2_0 | @@ -82,7 +82,7 @@ pub async fn handle_object_fal( }).await } _ => { - return Err(InternalObjectError::AnyhowError(anyhow!("Wrong model specified: {:?}", request.model))); + return Err(GenerateError::AnyhowError(anyhow!("Wrong model specified: {:?}", request.model))); } }; @@ -106,7 +106,7 @@ pub async fn handle_object_fal( if let Err(err) = fal_task_queue.insert(&enqueued) { error!("Failed to enqueue task: {:?}", err); - return Err(InternalObjectError::AnyhowError(anyhow!("Failed to enqueue task: {:?}", err))); + return Err(GenerateError::AnyhowError(anyhow!("Failed to enqueue task: {:?}", err))); } } Err(err) => { @@ -123,7 +123,7 @@ pub async fn handle_object_fal( error!("Failed to emit event: {:?}", err); // Fail open. } - return Err(InternalObjectError::FalError(err)); + return Err(GenerateError::from(err)); } } diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/internal_object_error.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/internal_object_error.rs deleted file mode 100644 index 5a60d077e5..0000000000 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/internal_object_error.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::core::artcraft_error::ArtcraftError; -use base64::DecodeError; -use errors::AnyhowError; -use fal_client::error::fal_error_plus::FalErrorPlus; -use storyteller_client::error::storyteller_error::StorytellerError; - -#[derive(Debug)] -pub enum InternalObjectError { - NoModelSpecified, - NoProviderAvailable, - NeedsFalApiKey, - NeedsSoraCredentials, - NeedsStorytellerCredentials, - FalError(FalErrorPlus), - AnyhowError(AnyhowError), - StorytellerError(StorytellerError), - DecodeError(DecodeError), - IoError(std::io::Error), - ArtcraftError(ArtcraftError), -} - -impl From for InternalObjectError { - fn from(value: AnyhowError) -> Self { - Self::AnyhowError(value) - } -} - -impl From for InternalObjectError { - fn from(value: FalErrorPlus) -> Self { - Self::FalError(value) - } -} - -impl From for InternalObjectError { - fn from(value: StorytellerError) -> Self { - Self::StorytellerError(value) - } -} - -impl From for InternalObjectError { - fn from(value: DecodeError) -> Self { - Self::DecodeError(value) - } -} - -impl From for InternalObjectError { - fn from(value: std::io::Error) -> Self { - Self::IoError(value) - } -} - -impl From for InternalObjectError { - fn from(value: ArtcraftError) -> Self { - match value { - ArtcraftError::AnyhowError(e) => Self::AnyhowError(e), - ArtcraftError::DecodeError(e) => Self::DecodeError(e), - ArtcraftError::IoError(e) => Self::IoError(e), - ArtcraftError::StorytellerError(e) => Self::StorytellerError(e), - _ => Self::ArtcraftError(value), - } - } -} diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/mod.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/mod.rs index 4ea85d22f0..db9c343df6 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/mod.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_object/mod.rs @@ -1,3 +1,2 @@ pub mod enqueue_image_to_3d_object_command; -pub mod internal_object_error; mod generic; \ No newline at end of file diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_video/generic/handle_video_fal.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_video/generic/handle_video_fal.rs index 33cb2836f4..b62fc5c4b6 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_video/generic/handle_video_fal.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_video/generic/handle_video_fal.rs @@ -57,7 +57,7 @@ pub async fn handle_video_fal( &media_token ).await?; } else { - return Err(GenerateError::BadInput(BadInputReason::ImageMissing)); + return Err(GenerateError::BadInput(BadInputReason::NoImageSpecified)); } let filename = temp_download.path().to_path_buf();