pub enum GcopError {
Show 21 variants
Git(GitErrorWrapper),
GitCommand(String),
Config(String),
Llm(String),
LlmStreamTruncated {
provider: String,
detail: String,
},
LlmContentBlocked {
provider: String,
reason: String,
},
LlmTimeout {
provider: String,
detail: String,
},
LlmConnectionFailed {
provider: String,
detail: String,
},
LlmApi {
status: u16,
message: String,
},
Network(Error),
Io(Error),
Serde(Error),
ConfigParse(ConfigError),
Inquire(InquireError),
NoStagedChanges,
UserCancelled,
InvalidInput(String),
MaxRetriesExceeded(usize),
SplitCommitPartial {
completed: usize,
total: usize,
detail: String,
},
SplitParseFailed(String),
Other(String),
}Expand description
gcop-rs unified error types
Contains all possible error conditions, supporting:
- Internationalized error messages (via
localized_message()) - User-friendly solution suggestions (via
localized_suggestion()) - Automatic conversion from various library errors (implementing
From<T>)
§Error category
- Git operation errors:
GitCommand,Git - LLM related errors:
Llm,LlmApi - Configuration errors:
Config,ConfigParse - User operations:
UserCancelled,InvalidInput - Others:
Io,Network,Other
§Example
use gcop_rs::error::{GcopError, Result};
fn example() -> Result<()> {
let err = GcopError::NoStagedChanges;
println!("Error: {}", err.localized_message());
if let Some(suggestion) = err.localized_suggestion() {
println!("Suggestion: {}", suggestion);
}
Err(err)
}Variants§
Git(GitErrorWrapper)
Git2 library error (libgit2)
Contains detailed ErrorCode and ErrorClass.
§Common error codes
NotFound: file/branch does not existExists: branch already existsUncommitted: There are uncommitted changesConflict: merge conflict
GitCommand(String)
Git command execution failed
Contains the stderr output of the git command.
§Common reasons
- No staged changes:
nothing to commit - pre-commit hook failed
- merge conflicts
Config(String)
Configuration error
Including configuration file errors, environment variable errors, missing API keys, etc.
Llm(String)
LLM provider error
Generic LLM errors (non-HTTP status code errors).
§Common reasons
- Response parsing failed
- No candidates/choices in response
LlmStreamTruncated
LLM stream unexpectedly truncated
The streaming response ended without a proper termination signal
(e.g. no message_stop from Claude, no [DONE] from OpenAI).
Fields
LlmContentBlocked
LLM response blocked by content policy
The provider refused to generate a response due to safety filters (e.g. Gemini SAFETY or RECITATION finish reason).
LlmTimeout
LLM request timeout
The HTTP request to the LLM API timed out before receiving a response.
Fields
LlmConnectionFailed
LLM connection failed
Could not establish a connection to the LLM API endpoint.
Fields
LlmApi
LLM API HTTP Error
Contains HTTP status codes and error messages.
§Common status codes
401- API key is invalid or expired429- rate limit500+- Server error
Network(Error)
network error
HTTP request failed (timeout, DNS error, connection refused, etc.).
Io(Error)
IO error
File reading and writing failed.
Serde(Error)
serialization error
JSON serialization/deserialization failed.
ConfigParse(ConfigError)
Configuration file parsing error
The TOML file is malformed or the field types do not match.
Inquire(InquireError)
UI interaction errors
Terminal interaction failed (user input error, terminal unavailable, etc.).
NoStagedChanges
No staged changes
The staging area is empty and the commit message cannot be generated.
UserCancelled
User cancels operation
The user chooses to exit at the interactive prompt.
InvalidInput(String)
Invalid input
The user-supplied parameter does not conform to the expected format.
MaxRetriesExceeded(usize)
Maximum number of retries reached
The number of commit message generation retries exceeds the configured upper limit.
SplitCommitPartial
Split commit partially failed.
Some commit groups succeeded while a later group failed.
Fields
SplitParseFailed(String)
Split response parsing failed.
The LLM response could not be parsed as valid commit groups.
Other(String)
Common error types
Used for errors that do not fit into other categories.
Implementations§
Source§impl GcopError
impl GcopError
Sourcepub fn localized_message(&self) -> String
pub fn localized_message(&self) -> String
Get localized error messages
Returns a translated error message based on the current locale.
§Returns
Localized error message string
§Example
use gcop_rs::error::GcopError;
let err = GcopError::NoStagedChanges;
println!("{}", err.localized_message());
// Output: No staged changes found (English environment)
// Output: No staged changes found (Chinese environment)Sourcepub fn localized_suggestion(&self) -> Option<String>
pub fn localized_suggestion(&self) -> Option<String>
Get localized solutions
Returns user-friendly resolution suggestions based on the error type (if any).
§Returns
Some(suggestion)- solution suggestion stringNone- no specific suggestions
§Suggestion type
- NoStagedChanges: Prompt to run
git add - Config(API key): Prompt to set API key
- LlmApi(401): Prompt to check API key validity
- LlmApi(429): Prompt to try again later or upgrade the API plan
- Network: Prompt to check network connection
- Other errors: may return
None
§Example
use gcop_rs::error::GcopError;
let err = GcopError::NoStagedChanges;
if let Some(suggestion) = err.localized_suggestion() {
println!("Try: {}", suggestion);
}
// Output: Try: Run 'git add <files>' to stage your changes firstTrait Implementations§
Source§impl Error for GcopError
impl Error for GcopError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<ConfigError> for GcopError
impl From<ConfigError> for GcopError
Source§fn from(source: ConfigError) -> Self
fn from(source: ConfigError) -> Self
Source§impl From<InquireError> for GcopError
impl From<InquireError> for GcopError
Source§fn from(source: InquireError) -> Self
fn from(source: InquireError) -> Self
Auto Trait Implementations§
impl Freeze for GcopError
impl !RefUnwindSafe for GcopError
impl Send for GcopError
impl Sync for GcopError
impl Unpin for GcopError
impl UnsafeUnpin for GcopError
impl !UnwindSafe for GcopError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.