Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 20 variants Repository(RepositoryError), Object(ObjectError), Index(IndexError), Ref(RefError), Revision(RevisionError), Config(ConfigError), Worktree(WorktreeError), Diff(DiffError), Commit(CommitError), Merge(MergeError), History(HistoryError), Stash(StashError), Branch(BranchError), Tag(TagError), Notes(NotesError), Remote(RemoteError), Hook(HookError), Io(Error), LockHeld(LockHeldError), Cancelled,
}
Expand description

The top-level error type for all grit-lib operations.

Every variant is one functional area (plus the cross-cutting Self::Io, Self::LockHeld and Self::Cancelled). Each area enum carries that area’s specific failures with structured fields; match on the area first, then on its enum.

§Examples

use grit_lib::error::{Error, ObjectError};

let err = Error::Object(ObjectError::NotFound { name: "1234abcd".into() });
assert_eq!(err.area(), "object");
assert_eq!(err.kind_name(), "object_not_found");
assert!(matches!(err, Error::Object(ObjectError::NotFound { .. })));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Repository(RepositoryError)

Repository discovery, layout, format, and maintenance-lock failures.

§

Object(ObjectError)

Object database, pack, commit-graph, multi-pack-index, and promisor failures.

§

Index(IndexError)

Index read, write, extension, or write-tree failure.

§

Ref(RefError)

Reference, reflog, ref store, and HEAD state failures.

§

Revision(RevisionError)

Revision lookup, parsing, and walk failures.

§

Config(ConfigError)

Configuration parse, validation, and write failures.

§

Worktree(WorktreeError)

Work tree, path, pathspec, checkout, filter, submodule, and linked worktree failures.

§

Diff(DiffError)

Patch application, hunk selection, and blame failures.

§

Commit(CommitError)

Commit, identity, signing, and patch-scoped commit failures.

§

Merge(MergeError)

Merge, cherry-pick, revert, and in-progress operation failures.

§

History(HistoryError)

History rewrite (grit history, rebase) failures.

§

Stash(StashError)

Stash push, apply, and stack failures.

§

Branch(BranchError)

Branch create, delete, lookup, and upstream configuration failures.

§

Tag(TagError)

Tag create, delete, and verification failures.

§

Notes(NotesError)

Notes ref, notes tree, and notes merge failures.

§

Remote(RemoteError)

Remote transport, fetch, push, and clone failures.

§

Hook(HookError)

A Git hook subprocess failed or could not be started.

§

Io(Error)

An I/O error from the underlying filesystem.

§

LockHeld(LockHeldError)

A lock file (for example .git/index.lock or refs/heads/main.lock) already exists, so another process is updating the same file or a crashed one left the lock behind.

Operations that return this before changing anything leave the repository untouched. The lock file belongs to whoever created it and is never removed. Retry once the other process finishes, or delete the lock path when no process owns it (a holder with running: false means the lock is stale).

§

Cancelled

A long-running library operation stopped at a cancellation checkpoint.

Use Error::is_cancelled to test for it, including cancellations recorded inside area errors.

Implementations§

Source§

impl Error

Source

pub fn kind_name(&self) -> &'static str

Stable snake_case name of this error’s specific failure (for example "not_a_repository"), for scripts and serialized output that must branch on the failure kind.

The names are the leaf failure names and change only when a failure is renamed. Match on the error value itself in Rust code.

§Examples
use grit_lib::error::Error;
use grit_lib::porcelain::CommitError;

assert_eq!(
    Error::Commit(CommitError::NothingToCommit).kind_name(),
    "nothing_to_commit"
);
assert_eq!(Error::Cancelled.kind_name(), "cancelled");
Source

pub fn area(&self) -> &'static str

Functional area of this error: the snake_case name of its umbrella variant ("repository", "object", "index", "ref", …).

§Examples
use grit_lib::error::Error;

assert_eq!(Error::Cancelled.area(), "cancelled");
Source

pub fn dirty_worktree( operation: WorktreeOperation, affected_paths: Vec<String>, ) -> Self

Build WorktreeError::DirtyWorktree, sorting and deduplicating paths.

Source

pub fn would_overwrite( reason: OverwriteReason, affected_paths: Vec<String>, ) -> Self

Build WorktreeError::WouldOverwrite for switch and similar tree transitions.

Source

pub fn remote_unreadable( url: impl Into<String>, reason: RemoteUnreadableReason, ) -> Self

Source

pub fn is_remote_unreadable(&self) -> bool

Whether this is an unreadable remote failure (see crate::remote::RemoteError::is_remote_unreadable).

Source

pub fn lock_held(&self) -> Option<&LockHeldError>

When this is Error::LockHeld, returns the structured lock failure.

Source

pub fn path_io(&self) -> Option<PathIoError>

When this is a worktree or git-dir path I/O failure, returns the shared leaf shape.

Source

pub fn is_worktree_file_in_use(&self) -> bool

Whether this is a work-tree path I/O failure caused by another process holding the file open (a Windows sharing or lock violation, EBUSY, or would-block), so retrying after closing that program can succeed.

Source

pub fn is_git_dir_file_in_use(&self) -> bool

Whether this is RepositoryError::git_dir_path_io caused by another process holding a git-dir file open (Windows sharing or access-denied during replace, EBUSY, …).

Source

pub fn is_cancelled(&self) -> bool

Whether this is Error::Cancelled or an area failure recording a cancellation.

Source

pub fn is_damaged_object(&self) -> bool

Whether an object read failed because a stored copy is damaged (zlib/header/truncation), so composite stores may consult the next backend.

Source

pub fn invalid_path_component( path: impl Into<String>, reason: PathComponentError, ) -> Self

Source

pub fn wants_fatal_prefix(&self) -> bool

When set, the CLI should prefix stderr with fatal: for Git-compatible commands.

Source

pub fn git_stderr_message(&self) -> String

Format for Git-style stderr (adds fatal: / error: when appropriate).

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

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<&Error> for ErrorSummary

Source§

fn from(err: &Error) -> Self

Converts to this type from the input type.
Source§

impl From<ApplyError> for Error

Source§

fn from(err: ApplyError) -> Self

Converts to this type from the input type.
Source§

impl From<AuthorArgError> for Error

Source§

fn from(err: AuthorArgError) -> Self

Converts to this type from the input type.
Source§

impl From<BitmapError> for Error

Source§

fn from(err: BitmapError) -> Self

Converts to this type from the input type.
Source§

impl From<BitmapWalkError> for Error

Source§

fn from(err: BitmapWalkError) -> Self

Converts to this type from the input type.
Source§

impl From<BitmapWalkUnsupported> for Error

Source§

fn from(err: BitmapWalkUnsupported) -> Self

Converts to this type from the input type.
Source§

impl From<BranchError> for Error

Source§

fn from(source: BranchError) -> Self

Converts to this type from the input type.
Source§

impl From<BundleError> for Error

Source§

fn from(err: BundleError) -> Self

Converts to this type from the input type.
Source§

impl From<Cancelled> for Error

Source§

fn from(_: Cancelled) -> Self

Converts to this type from the input type.
Source§

impl From<ChangeIdError> for Error

Source§

fn from(err: ChangeIdError) -> Self

Converts to this type from the input type.
Source§

impl From<CheckoutError> for Error

Source§

fn from(err: CheckoutError) -> Self

Converts to this type from the input type.
Source§

impl From<CloneError> for Error

Source§

fn from(err: CloneError) -> Self

Converts to this type from the input type.
Source§

impl From<CommitError> for Error

Source§

fn from(err: CommitError) -> Self

Converts to this type from the input type.
Source§

impl From<CommitIdentityError> for Error

Source§

fn from(err: CommitIdentityError) -> Self

Converts to this type from the input type.
Source§

impl From<ConfigError> for Error

Source§

fn from(source: ConfigError) -> Self

Converts to this type from the input type.
Source§

impl From<DiffError> for Error

Source§

fn from(source: DiffError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ErrorSummary

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for UnpackError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FetchRefspecError> for Error

Source§

fn from(e: FetchRefspecError) -> Self

Converts to this type from the input type.
Source§

impl From<FilterError> for Error

Source§

fn from(err: FilterError) -> Self

Converts to this type from the input type.
Source§

impl From<FuncnamePatternError> for Error

Source§

fn from(err: FuncnamePatternError) -> Self

Converts to this type from the input type.
Source§

impl From<HistoryError> for Error

Source§

fn from(err: HistoryError) -> Self

Converts to this type from the input type.
Source§

impl From<HookError> for Error

Source§

fn from(err: HookError) -> Self

Converts to this type from the input type.
Source§

impl From<HunkSelectError> for Error

Source§

fn from(err: HunkSelectError) -> Self

Converts to this type from the input type.
Source§

impl From<IdentityError> for Error

Source§

fn from(err: IdentityError) -> Self

Converts to this type from the input type.
Source§

impl From<IndexError> for Error

Source§

fn from(err: IndexError) -> Self

Converts to this type from the input type.
Source§

impl From<LinkedWorktreeError> for Error

Source§

fn from(value: LinkedWorktreeError) -> Self

Converts to this type from the input type.
Source§

impl From<LockError> for Error

Source§

fn from(err: LockError) -> Self

LockError::Held becomes Error::LockHeld with the recorded LockHolder, and I/O failures become Error::Io.

Source§

impl From<LockHeldError> for Error

Source§

fn from(source: LockHeldError) -> Self

Converts to this type from the input type.
Source§

impl From<MergeError> for Error

Source§

fn from(err: MergeError) -> Self

Converts to this type from the input type.
Source§

impl From<MidxError> for Error

Source§

fn from(err: MidxError) -> Self

Converts to this type from the input type.
Source§

impl From<NoIndexError> for Error

Source§

fn from(value: NoIndexError) -> Self

Converts to this type from the input type.
Source§

impl From<NotesError> for Error

Source§

fn from(source: NotesError) -> Self

Converts to this type from the input type.
Source§

impl From<ObjectError> for Error

Source§

fn from(source: ObjectError) -> Self

Converts to this type from the input type.
Source§

impl From<OffloadError> for Error

Source§

fn from(err: OffloadError) -> Self

Converts to this type from the input type.
Source§

impl From<PathIoError> for Error

Source§

fn from(value: PathIoError) -> Self

Converts to this type from the input type.
Source§

impl From<PathOutsideRepoError> for Error

Source§

fn from(err: PathOutsideRepoError) -> Self

Converts to this type from the input type.
Source§

impl From<PathspecFromFileParseError> for Error

Source§

fn from(err: PathspecFromFileParseError) -> Self

Converts to this type from the input type.
Source§

impl From<PickaxeError> for Error

Source§

fn from(value: PickaxeError) -> Self

Converts to this type from the input type.
Source§

impl From<PullError> for Error

Source§

fn from(err: PullError) -> Self

Converts to this type from the input type.
Source§

impl From<PushPlanError> for Error

Source§

fn from(err: PushPlanError) -> Self

Converts to this type from the input type.
Source§

impl From<RebaseSessionError> for Error

Source§

fn from(err: RebaseSessionError) -> Self

Converts to this type from the input type.
Source§

impl From<RefError> for Error

Source§

fn from(source: RefError) -> Self

Converts to this type from the input type.
Source§

impl From<RefLockError> for Error

Source§

fn from(err: RefLockError) -> Self

Converts to this type from the input type.
Source§

impl From<RefStoreError> for Error

Source§

fn from(err: RefStoreError) -> Self

Converts to this type from the input type.
Source§

impl From<ReftableError> for Error

Source§

fn from(err: ReftableError) -> Self

Converts to this type from the input type.
Source§

impl From<RemoteError> for Error

Source§

fn from(err: RemoteError) -> Self

Converts to this type from the input type.
Source§

impl From<RepositoryError> for Error

Source§

fn from(source: RepositoryError) -> Self

Converts to this type from the input type.
Source§

impl From<ResolveDiffArgumentsError> for Error

Source§

fn from(err: ResolveDiffArgumentsError) -> Self

Converts to this type from the input type.
Source§

impl From<ResolveError> for Error

Source§

fn from(err: ResolveError) -> Self

Converts to this type from the input type.
Source§

impl From<ResumableError> for Error

Source§

fn from(err: ResumableError) -> Self

Converts to this type from the input type.
Source§

impl From<RevListError> for Error

Source§

fn from(err: RevListError) -> Self

Converts to this type from the input type.
Source§

impl From<RevParseError> for Error

Source§

fn from(err: RevParseError) -> Self

Converts to this type from the input type.
Source§

impl From<RevisionError> for Error

Source§

fn from(source: RevisionError) -> Self

Converts to this type from the input type.
Source§

impl From<ServeError> for Error

Source§

fn from(err: ServeError) -> Self

Converts to this type from the input type.
Source§

impl From<SignatureError> for Error

Source§

fn from(err: SignatureError) -> Self

Converts to this type from the input type.
Source§

impl From<StashError> for Error

Source§

fn from(err: StashError) -> Self

Converts to this type from the input type.
Source§

impl From<StashPushValidationError> for Error

Source§

fn from(err: StashPushValidationError) -> Self

Converts to this type from the input type.
Source§

impl From<SubmoduleError> for Error

Source§

fn from(err: SubmoduleError) -> Self

Converts to this type from the input type.
Source§

impl From<TagError> for Error

Source§

fn from(source: TagError) -> Self

Converts to this type from the input type.
Source§

impl From<TreeEntryError> for Error

Source§

fn from(err: TreeEntryError) -> Self

Converts to this type from the input type.
Source§

impl From<TreeSha256ClaimError> for Error

Source§

fn from(err: TreeSha256ClaimError) -> Self

Converts to this type from the input type.
Source§

impl From<WorktreeError> for Error

Source§

fn from(source: WorktreeError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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, 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> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.