Download crates/forge_domain/src/error.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 5.05 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_domain/src/error.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_domain/src/error.rs
-
curl -L -o error.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_domain/src/error.rs
5.05 kB
| use std::pin::Pin; | |
| use derive_more::From; | |
| use forge_json_repair::JsonRepairError; | |
| use thiserror::Error; | |
| use crate::{AgentId, ConversationId, ProviderId, WorkspaceId}; | |
| // NOTE: Deriving From for error is a really bad idea. This is because you end | |
| // up converting errors incorrectly without much context. For eg: You don't want | |
| // all serde error to be treated as the same. Instead we want to know exactly | |
| // where that serde failure happened and for what kind of value. | |
| pub enum Error { | |
| ToolCallMissingName, | |
| ToolCallMissingId, | |
| UnsupportedRole(String), | |
| EToolCallArgument(ToolCallArgumentError), | |
| ToolCallArgument { | |
| error: JsonRepairError, | |
| args: String, | |
| }, | |
| AgentCallArgument { error: serde_json::error::Error }, | |
| ToolCallParse(String), | |
| ConversationId(uuid::Error), | |
| AgentUndefined(AgentId), | |
| UndefinedVariable(String), | |
| HeadAgentUndefined, | |
| MaxTurnsReached(AgentId, u64), | |
| ConversationNotFound(ConversationId), | |
| MissingAgentDescription(AgentId), | |
| MissingModel(AgentId), | |
| NoModelDefined(AgentId), | |
| EmptyCompletion, | |
| Refusal, | |
| Retryable(anyhow::Error), | |
| EnvironmentVariableNotFound { | |
| provider: ProviderId, | |
| env_var: String, | |
| }, | |
| ProviderNotAvailable { provider: ProviderId }, | |
| VertexAiConfiguration { message: String }, | |
| // Indexing errors | |
| AuthTokenNotFound, | |
| WorkspaceNotFound, | |
| WorkspaceAlreadyInitialized(WorkspaceId), | |
| SyncFailed { count: usize }, | |
| NoDefaultSession, | |
| } | |
| pub type Result<A> = std::result::Result<A, Error>; | |
| pub type BoxStream<A, E> = | |
| Pin<Box<dyn tokio_stream::Stream<Item = std::result::Result<A, E>> + Send>>; | |
| pub type ResultStream<A, E> = std::result::Result<BoxStream<A, E>, E>; | |
| pub struct ToolCallArgumentError(eserde::DeserializationErrors); | |
| impl std::error::Error for ToolCallArgumentError {} | |
| impl std::fmt::Display for ToolCallArgumentError { | |
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| writeln!(f, "Invalid tool call arguments:")?; | |
| for error in self.0.iter() { | |
| writeln!(f, "- {error}")?; | |
| } | |
| Ok(()) | |
| } | |
| } | |
| impl Error { | |
| pub fn into_retryable(self) -> Self { | |
| use anyhow::anyhow; | |
| Self::Retryable(anyhow!(self)) | |
| } | |
| pub fn env_var_not_found(provider: ProviderId, env_var: &str) -> Self { | |
| Self::EnvironmentVariableNotFound { provider, env_var: env_var.to_string() } | |
| } | |
| pub fn provider_not_available(provider: ProviderId) -> Self { | |
| Self::ProviderNotAvailable { provider } | |
| } | |
| pub fn vertex_ai_config(message: impl Into<String>) -> Self { | |
| Self::VertexAiConfiguration { message: message.into() } | |
| } | |
| pub fn sync_failed(count: usize) -> Self { | |
| Self::SyncFailed { count } | |
| } | |
| } | |
| mod test { | |
| use forge_json_repair::JsonRepairError; | |
| use serde_json::Value; | |
| use crate::Error; | |
| fn test_debug_serde_error() { | |
| let args = "{a: 1}"; | |
| let serde_error = serde_json::from_str::<Value>(args).unwrap_err(); | |
| let a = Error::ToolCallArgument { | |
| error: JsonRepairError::from(serde_error), | |
| args: args.to_string(), | |
| }; | |
| let a = anyhow::anyhow!(a); | |
| eprintln!("{:?}", a.root_cause()); | |
| } | |
| } | |