ok/jj
1
0
Fork 0
forked from mirrors/jj

repo: add a specific error type for MutableRepo::edit()

The new type is just an enum version of `RewriteRootCommit`.  I'll add
another variant soon.
This commit is contained in:
Martin von Zweigbergk 2023-01-22 21:02:41 -08:00 committed by Martin von Zweigbergk
parent ff592e522f
commit dd3472924b
2 changed files with 17 additions and 2 deletions

View file

@ -764,9 +764,10 @@ impl MutableRepo {
&mut self,
workspace_id: WorkspaceId,
commit: &Commit,
) -> Result<(), RewriteRootCommit> {
) -> Result<(), EditCommitError> {
self.leave_commit(&workspace_id);
self.set_wc_commit(workspace_id, commit.id().clone())
.map_err(|RewriteRootCommit| EditCommitError::RewriteRootCommit)
}
fn leave_commit(&mut self, workspace_id: &WorkspaceId) {
@ -1110,6 +1111,13 @@ impl MutableRepo {
#[error("Cannot rewrite the root commit")]
pub struct RewriteRootCommit;
/// Error from attempts to edit a commit
#[derive(Debug, Error)]
pub enum EditCommitError {
#[error("Cannot rewrite the root commit")]
RewriteRootCommit,
}
#[derive(Debug, Error)]
#[error("Cannot access {path}")]
pub struct PathError {

View file

@ -37,7 +37,8 @@ use jujutsu_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, WorkspaceId};
use jujutsu_lib::operation::Operation;
use jujutsu_lib::repo::{
MutableRepo, ReadonlyRepo, RepoLoader, RepoRef, RewriteRootCommit, StoreFactories,
EditCommitError, MutableRepo, ReadonlyRepo, RepoLoader, RepoRef, RewriteRootCommit,
StoreFactories,
};
use jujutsu_lib::repo_path::{FsPathParseError, RepoPath};
use jujutsu_lib::revset::{
@ -117,6 +118,12 @@ impl From<RewriteRootCommit> for CommandError {
}
}
impl From<EditCommitError> for CommandError {
fn from(err: EditCommitError) -> Self {
CommandError::InternalError(format!("Failed to edit a commit: {err}"))
}
}
impl From<BackendError> for CommandError {
fn from(err: BackendError) -> Self {
user_error(format!("Unexpected error from backend: {err}"))