Skip to main content

GcopError

Enum GcopError 

Source
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:

§Error category

§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 exist
  • Exists: branch already exists
  • Uncommitted: There are uncommitted changes
  • Conflict: 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

§provider: String

Provider name (e.g. “Claude”, “OpenAI”)

§detail: String

Description of the truncation

§

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).

Fields

§provider: String

Provider name (e.g. “Gemini”)

§reason: String

Reason reported by the provider

§

LlmTimeout

LLM request timeout

The HTTP request to the LLM API timed out before receiving a response.

Fields

§provider: String

Provider name (e.g. “Claude”, “OpenAI”)

§detail: String

Error detail from the HTTP client

§

LlmConnectionFailed

LLM connection failed

Could not establish a connection to the LLM API endpoint.

Fields

§provider: String

Provider name (e.g. “Claude”, “OpenAI”)

§detail: String

Error detail from the HTTP client

§

LlmApi

LLM API HTTP Error

Contains HTTP status codes and error messages.

§Common status codes

  • 401 - API key is invalid or expired
  • 429 - rate limit
  • 500+ - Server error

Fields

§status: u16

HTTP status code

§message: String

error message

§

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

§completed: usize

Number of groups that committed successfully.

§total: usize

Total number of groups.

§detail: String

Error detail.

§

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

Source

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)
Source

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 string
  • None - 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 first

Trait Implementations§

Source§

impl Debug for GcopError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for GcopError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for GcopError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ConfigError> for GcopError

Source§

fn from(source: ConfigError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for GcopError

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for GcopError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for GcopError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for GcopError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<InquireError> for GcopError

Source§

fn from(source: InquireError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more