Skip to content

Commit 720e50d

Browse files
authored
Merge pull request #4200 from gitbutlerapp/refactor-move-error-marker
move error marker out of virtual_branches mod
2 parents 8f052c0 + b72f9c2 commit 720e50d

File tree

10 files changed

+36
-38
lines changed

10 files changed

+36
-38
lines changed

crates/gitbutler-core/src/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,30 @@ impl AnyhowContextExt for anyhow::Error {
231231
})
232232
}
233233
}
234+
235+
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
236+
/// that a certain even happened.
237+
///
238+
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
239+
/// to signify its marker status.
240+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
241+
pub enum Marker {
242+
/// Invalid state was detected, making the repository invalid for operation.
243+
VerificationFailure,
244+
/// An indicator for a conflict in the project.
245+
///
246+
/// See usages for details on what these conflicts can be.
247+
ProjectConflict,
248+
/// An indicator that a branch conflicted during applying to the workspace.
249+
BranchConflict,
250+
}
251+
252+
impl std::fmt::Display for Marker {
253+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
254+
match self {
255+
Marker::VerificationFailure => f.write_str("<verification-failed>"),
256+
Marker::ProjectConflict => f.write_str("<project-conflict>"),
257+
Marker::BranchConflict => f.write_str("<branch-conflict>"),
258+
}
259+
}
260+
}

crates/gitbutler-core/src/project_repository/repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
ssh, users,
1616
virtual_branches::{Branch, BranchId},
1717
};
18-
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
18+
use crate::{error::Marker, git::RepositoryExt};
1919

2020
pub struct Repository {
2121
git_repository: git2::Repository,

crates/gitbutler-core/src/rebase/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::{
2-
git::CommitExt, git::RepositoryExt, project_repository, virtual_branches::errors::Marker,
3-
};
1+
use crate::{error::Marker, git::CommitExt, git::RepositoryExt, project_repository};
42
use anyhow::{anyhow, Context, Result};
53
use bstr::ByteSlice;
64

crates/gitbutler-core/src/virtual_branches/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::{
1111
},
1212
target, BranchId, RemoteCommit, VirtualBranchHunk, VirtualBranchesHandle,
1313
};
14-
use crate::{git::RepositoryExt, rebase::cherry_rebase, virtual_branches::errors::Marker};
14+
use crate::{error::Marker, git::RepositoryExt, rebase::cherry_rebase};
1515
use crate::{
1616
git::{self, diff},
1717
project_repository::{self, LogUntil},

crates/gitbutler-core/src/virtual_branches/errors.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

crates/gitbutler-core/src/virtual_branches/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use bstr::ByteSlice;
55
use lazy_static::lazy_static;
66

77
use super::VirtualBranchesHandle;
8+
use crate::error::Marker;
89
use crate::git::RepositoryExt;
9-
use crate::virtual_branches::errors::Marker;
1010
use crate::{
1111
git::{self, CommitExt},
1212
project_repository::{self, conflicts, LogUntil},

crates/gitbutler-core/src/virtual_branches/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ pub mod branch;
22
pub use branch::{Branch, BranchId};
33
pub mod target;
44

5-
pub mod errors;
6-
75
mod files;
86
pub use files::*;
97

crates/gitbutler-core/src/virtual_branches/virtual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use super::{
2626
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
2727
};
2828
use crate::error::Code;
29+
use crate::error::Marker;
2930
use crate::git::diff::GitHunk;
3031
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
3132
use crate::git::{CommitExt, RepositoryExt};
3233
use crate::rebase::{cherry_rebase, cherry_rebase_group};
3334
use crate::time::now_since_unix_epoch_ms;
3435
use crate::virtual_branches::branch::HunkHash;
35-
use crate::virtual_branches::errors::Marker;
3636
use crate::{
3737
dedup::{dedup, dedup_fmt},
3838
git::{

crates/gitbutler-core/tests/suite/virtual_branches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22
use std::{fs, path, str::FromStr};
33

4-
use gitbutler_core::virtual_branches::errors::Marker;
4+
use gitbutler_core::error::Marker;
55
use gitbutler_core::{
66
git,
77
projects::{self, Project, ProjectId},

crates/gitbutler-watcher/src/handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::PathBuf;
22
use std::sync::Arc;
33

44
use anyhow::{Context, Result};
5+
use gitbutler_core::error::Marker;
56
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
67
use gitbutler_core::projects::ProjectId;
78
use gitbutler_core::synchronize::sync_with_gitbutler;
@@ -101,8 +102,8 @@ impl Handler {
101102
}
102103
Err(err)
103104
if matches!(
104-
err.downcast_ref::<virtual_branches::errors::Marker>(),
105-
Some(virtual_branches::errors::Marker::VerificationFailure)
105+
err.downcast_ref::<Marker>(),
106+
Some(Marker::VerificationFailure)
106107
) =>
107108
{
108109
Ok(())

0 commit comments

Comments
 (0)