use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum NotesError {
#[error("note for object {object} already exists")]
AlreadyExists {
object: crate::objects::ObjectId,
},
#[error("notes ref '{name}' must start with 'refs/notes/'")]
InvalidRef {
name: String,
},
#[error("unknown notes rewrite mode '{mode}'")]
UnknownRewriteMode {
mode: String,
},
#[error("notes ref '{notes_ref}' points to a {found}, not a notes commit")]
RefNotCommit {
notes_ref: String,
found: crate::objects::ObjectKind,
},
#[error("notes object {oid} is a {found}, expected a {expected}")]
UnexpectedObjectKind {
oid: crate::objects::ObjectId,
expected: crate::objects::ObjectKind,
found: crate::objects::ObjectKind,
},
#[error("cannot merge notes: neither '{local}' nor '{remote}' has any notes")]
MergeBothEmpty {
local: String,
remote: String,
},
#[error("unfinished notes merge: conflict files remain in {}", crate::git_path::user_display_path(.path))]
MergeInProgress {
path: std::path::PathBuf,
},
}
impl NotesError {
#[must_use]
pub fn kind_name(&self) -> &'static str {
match self {
Self::AlreadyExists { .. } => "note_already_exists",
Self::InvalidRef { .. } => "invalid_notes_ref",
Self::UnknownRewriteMode { .. } => "notes_rewrite_mode",
Self::RefNotCommit { .. } => "notes_ref_not_commit",
Self::UnexpectedObjectKind { .. } => "notes_object_kind",
Self::MergeBothEmpty { .. } => "notes_merge_both_empty",
Self::MergeInProgress { .. } => "notes_merge_in_progress",
}
}
}