From 2aaacdfca7787f9ce3bc03df98833c02ad06cf6e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 1 Apr 2024 15:57:09 +0200 Subject: [PATCH] chore: remove legacy error in favor of new error system --- crates/gitbutler-core/src/error.rs | 62 +-- crates/gitbutler-core/src/git/credentials.rs | 20 - .../src/project_repository/repository.rs | 35 -- .../gitbutler-core/src/projects/controller.rs | 6 +- .../gitbutler-core/src/sessions/controller.rs | 4 +- .../src/virtual_branches/controller.rs | 124 ++--- .../src/virtual_branches/errors.rs | 496 +----------------- .../src/virtual_branches/virtual.rs | 15 +- crates/gitbutler-core/src/zip/controller.rs | 6 +- gitbutler-app/src/app.rs | 10 +- gitbutler-app/src/commands.rs | 26 +- gitbutler-app/src/deltas.rs | 5 +- gitbutler-app/src/error.rs | 80 +-- gitbutler-app/src/github.rs | 6 +- gitbutler-app/src/keys.rs | 4 +- gitbutler-app/src/menu.rs | 5 +- gitbutler-app/src/projects.rs | 23 +- gitbutler-app/src/sessions.rs | 5 +- gitbutler-app/src/users.rs | 8 +- gitbutler-app/src/virtual_branches.rs | 61 +-- gitbutler-app/src/zip.rs | 9 +- 21 files changed, 174 insertions(+), 836 deletions(-) diff --git a/crates/gitbutler-core/src/error.rs b/crates/gitbutler-core/src/error.rs index 8651652de..c27dd191f 100644 --- a/crates/gitbutler-core/src/error.rs +++ b/crates/gitbutler-core/src/error.rs @@ -132,21 +132,21 @@ pub fn into_anyhow(err: impl ErrorWithContext + Send + Sync + 'static) -> anyhow /// Whenever `thiserror` is involved, this error type should be used if the alternative would be to write /// a `thiserror` which just forwards its context (like `app::Error` previously). #[derive(Debug)] -pub struct Error2(anyhow::Error); +pub struct Error(anyhow::Error); -impl From for Error2 { +impl From for Error { fn from(value: anyhow::Error) -> Self { Self(value) } } -impl From for anyhow::Error { - fn from(value: Error2) -> Self { +impl From for anyhow::Error { + fn from(value: Error) -> Self { value.0 } } -impl From for Error2 +impl From for Error where E: ErrorWithContext + Send + Sync + 'static, { @@ -155,7 +155,7 @@ where } } -impl Error2 { +impl Error { /// A manual, none-overlapping implementation of `From` (or else there are conflicts). pub fn from_err(err: impl std::error::Error + Send + Sync + 'static) -> Self { Self(err.into()) @@ -186,53 +186,3 @@ impl Error2 { self.0.downcast_ref::() } } - -pub(crate) use legacy::Error; -mod legacy { - use serde::{ser::SerializeMap, Serialize}; - - use crate::error::Code; - use crate::projects; - - #[derive(Debug, thiserror::Error)] - pub enum Error { - #[error("[{code}]: {message}")] - UserError { code: Code, message: String }, - #[error("[errors.unknown]: Something went wrong")] - Unknown, - } - - impl Serialize for Error { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - let (code, message) = match self { - Error::UserError { code, message } => (code.to_string(), message.to_string()), - Error::Unknown => ( - Code::Unknown.to_string(), - "Something went wrong".to_string(), - ), - }; - - let mut map = serializer.serialize_map(Some(2))?; - map.serialize_entry("code", &code)?; - map.serialize_entry("message", &message)?; - map.end() - } - } - - impl From for Error { - fn from(error: anyhow::Error) -> Self { - tracing::error!(?error); - Error::Unknown - } - } - - impl From for Error { - fn from(error: projects::controller::GetError) -> Self { - tracing::error!(?error); - Error::Unknown - } - } -} diff --git a/crates/gitbutler-core/src/git/credentials.rs b/crates/gitbutler-core/src/git/credentials.rs index 3c5102659..fd2326ff5 100644 --- a/crates/gitbutler-core/src/git/credentials.rs +++ b/crates/gitbutler-core/src/git/credentials.rs @@ -87,26 +87,6 @@ pub enum HelpError { Other(#[from] anyhow::Error), } -impl From for crate::error::Error { - fn from(value: HelpError) -> Self { - match value { - HelpError::NoUrlSet => Self::UserError { - code: crate::error::Code::ProjectGitRemote, - message: "no url set for remote".to_string(), - }, - HelpError::UrlConvertError(error) => Self::UserError { - code: crate::error::Code::ProjectGitRemote, - message: error.to_string(), - }, - HelpError::Git(error) => { - tracing::error!(?error, "failed to create auth credentials"); - Self::Unknown - } - HelpError::Other(error) => error.into(), - } - } -} - impl ErrorWithContext for HelpError { fn context(&self) -> Option { Some(match self { diff --git a/crates/gitbutler-core/src/project_repository/repository.rs b/crates/gitbutler-core/src/project_repository/repository.rs index 6aeee66c5..e80562764 100644 --- a/crates/gitbutler-core/src/project_repository/repository.rs +++ b/crates/gitbutler-core/src/project_repository/repository.rs @@ -32,21 +32,6 @@ pub enum OpenError { Other(anyhow::Error), } -impl From for crate::error::Error { - fn from(value: OpenError) -> Self { - match value { - OpenError::NotFound(path) => crate::error::Error::UserError { - code: crate::error::Code::Projects, - message: format!("{} not found", path.display()), - }, - OpenError::Other(error) => { - tracing::error!(?error); - crate::error::Error::Unknown - } - } - } -} - impl ErrorWithContext for OpenError { fn context(&self) -> Option { match self { @@ -640,26 +625,6 @@ pub enum RemoteError { Other(#[from] anyhow::Error), } -impl From for crate::error::Error { - fn from(value: RemoteError) -> Self { - match value { - RemoteError::Help(error) => error.into(), - RemoteError::Network => crate::error::Error::UserError { - code: crate::error::Code::ProjectGitRemote, - message: "Network erorr occured".to_string(), - }, - RemoteError::Auth => crate::error::Error::UserError { - code: crate::error::Code::ProjectGitAuth, - message: "Project remote authentication error".to_string(), - }, - RemoteError::Other(error) => { - tracing::error!(?error); - crate::error::Error::Unknown - } - } - } -} - impl ErrorWithContext for RemoteError { fn context(&self) -> Option { Some(match self { diff --git a/crates/gitbutler-core/src/projects/controller.rs b/crates/gitbutler-core/src/projects/controller.rs index aa5f01af0..a05c5895f 100644 --- a/crates/gitbutler-core/src/projects/controller.rs +++ b/crates/gitbutler-core/src/projects/controller.rs @@ -7,7 +7,7 @@ use anyhow::{Context, Result}; use async_trait::async_trait; use super::{storage, storage::UpdateRequest, Project, ProjectId}; -use crate::error::{AnyhowContextExt, Code, Error2, ErrorWithContext}; +use crate::error::{AnyhowContextExt, Code, Error, ErrorWithContext}; use crate::{error, gb_repository, project_repository, users}; #[async_trait] @@ -199,11 +199,11 @@ impl Controller { self.projects_storage.list().map_err(Into::into) } - pub async fn delete(&self, id: &ProjectId) -> Result<(), Error2> { + pub async fn delete(&self, id: &ProjectId) -> Result<(), Error> { let project = match self.projects_storage.get(id) { Ok(project) => Ok(project), Err(super::storage::Error::NotFound) => return Ok(()), - Err(error) => Err(Error2::from_err(error)), + Err(error) => Err(Error::from_err(error)), }?; if let Some(watchers) = &self.watchers { diff --git a/crates/gitbutler-core/src/sessions/controller.rs b/crates/gitbutler-core/src/sessions/controller.rs index b45cdd2b6..968fb532e 100644 --- a/crates/gitbutler-core/src/sessions/controller.rs +++ b/crates/gitbutler-core/src/sessions/controller.rs @@ -3,7 +3,7 @@ use std::path; use anyhow::Context; use super::{Database, Session}; -use crate::error::Error2; +use crate::error::Error; use crate::{ gb_repository, project_repository, projects::{self, ProjectId}, @@ -38,7 +38,7 @@ impl Controller { &self, project_id: &ProjectId, earliest_timestamp_ms: Option, - ) -> Result, Error2> { + ) -> Result, Error> { let sessions = self .sessions_database .list_by_project_id(project_id, earliest_timestamp_ms)?; diff --git a/crates/gitbutler-core/src/virtual_branches/controller.rs b/crates/gitbutler-core/src/virtual_branches/controller.rs index 7541b19d2..f4171f309 100644 --- a/crates/gitbutler-core/src/virtual_branches/controller.rs +++ b/crates/gitbutler-core/src/virtual_branches/controller.rs @@ -1,4 +1,4 @@ -use crate::error::Error2; +use crate::error::Error; use std::{collections::HashMap, path, sync::Arc}; use anyhow::Context; @@ -71,7 +71,7 @@ impl Controller { message: &str, ownership: Option<&BranchOwnershipClaims>, run_hooks: bool, - ) -> Result { + ) -> Result { self.inner(project_id) .await .create_commit(project_id, branch_id, message, ownership, run_hooks) @@ -82,7 +82,7 @@ impl Controller { &self, project_id: &ProjectId, branch_name: &git::RemoteRefname, - ) -> Result { + ) -> Result { self.inner(project_id) .await .can_apply_remote_branch(project_id, branch_name) @@ -92,7 +92,7 @@ impl Controller { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result { + ) -> Result { self.inner(project_id) .await .can_apply_virtual_branch(project_id, branch_id) @@ -103,7 +103,7 @@ impl Controller { &self, project_id: &ProjectId, branch_ids: Vec, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let vbranches_state = self .inner(project_id) .await @@ -126,7 +126,7 @@ impl Controller { pub async fn list_virtual_branches( &self, project_id: &ProjectId, - ) -> Result<(Vec, bool, Vec), Error2> { + ) -> Result<(Vec, bool, Vec), Error> { self.inner(project_id) .await .list_virtual_branches(project_id) @@ -137,7 +137,7 @@ impl Controller { &self, project_id: &ProjectId, create: &super::branch::BranchCreateRequest, - ) -> Result { + ) -> Result { self.inner(project_id) .await .create_virtual_branch(project_id, create) @@ -148,7 +148,7 @@ impl Controller { &self, project_id: &ProjectId, branch: &git::Refname, - ) -> Result { + ) -> Result { self.inner(project_id) .await .create_virtual_branch_from_branch(project_id, branch) @@ -158,7 +158,7 @@ impl Controller { pub async fn get_base_branch_data( &self, project_id: &ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { self.inner(project_id) .await .get_base_branch_data(project_id) @@ -168,7 +168,7 @@ impl Controller { &self, project_id: &ProjectId, commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { self.inner(project_id) .await .list_remote_commit_files(project_id, commit_oid) @@ -178,7 +178,7 @@ impl Controller { &self, project_id: &ProjectId, target_branch: &git::RemoteRefname, - ) -> Result { + ) -> Result { self.inner(project_id) .await .set_base_branch(project_id, target_branch) @@ -188,14 +188,14 @@ impl Controller { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .merge_virtual_branch_upstream(project_id, branch_id) .await } - pub async fn update_base_branch(&self, project_id: &ProjectId) -> Result<(), Error2> { + pub async fn update_base_branch(&self, project_id: &ProjectId) -> Result<(), Error> { self.inner(project_id) .await .update_base_branch(project_id) @@ -206,7 +206,7 @@ impl Controller { &self, project_id: &ProjectId, branch_update: super::branch::BranchUpdateRequest, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .update_virtual_branch(project_id, branch_update) @@ -216,7 +216,7 @@ impl Controller { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .delete_virtual_branch(project_id, branch_id) @@ -227,7 +227,7 @@ impl Controller { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .apply_virtual_branch(project_id, branch_id) @@ -238,7 +238,7 @@ impl Controller { &self, project_id: &ProjectId, ownership: &BranchOwnershipClaims, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .unapply_ownership(project_id, ownership) @@ -249,7 +249,7 @@ impl Controller { &self, project_id: &ProjectId, files: &Vec, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .reset_files(project_id, files) @@ -261,7 +261,7 @@ impl Controller { project_id: &ProjectId, branch_id: &BranchId, ownership: &BranchOwnershipClaims, - ) -> Result { + ) -> Result { self.inner(project_id) .await .amend(project_id, branch_id, ownership) @@ -273,7 +273,7 @@ impl Controller { project_id: &ProjectId, branch_id: &BranchId, target_commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .reset_virtual_branch(project_id, branch_id, target_commit_oid) @@ -284,7 +284,7 @@ impl Controller { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .unapply_virtual_branch(project_id, branch_id) @@ -297,7 +297,7 @@ impl Controller { branch_id: &BranchId, with_force: bool, askpass: Option<(AskpassBroker, Option)>, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .push_virtual_branch(project_id, branch_id, with_force, askpass) @@ -309,7 +309,7 @@ impl Controller { project_id: &ProjectId, branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { self.inner(project_id) .await .cherry_pick(project_id, branch_id, commit_oid) @@ -319,7 +319,7 @@ impl Controller { pub async fn list_remote_branches( &self, project_id: &ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { self.inner(project_id) .await .list_remote_branches(project_id) @@ -329,7 +329,7 @@ impl Controller { &self, project_id: &ProjectId, refname: &git::Refname, - ) -> Result { + ) -> Result { self.inner(project_id) .await .get_remote_branch_data(project_id, refname) @@ -340,7 +340,7 @@ impl Controller { project_id: &ProjectId, branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .squash(project_id, branch_id, commit_oid) @@ -353,7 +353,7 @@ impl Controller { branch_id: &BranchId, commit_oid: git::Oid, message: &str, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .update_commit_message(project_id, branch_id, commit_oid, message) @@ -364,7 +364,7 @@ impl Controller { &self, project_id: &ProjectId, askpass: Option<(AskpassBroker, String)>, - ) -> Result { + ) -> Result { self.inner(project_id) .await .fetch_from_target(project_id, askpass) @@ -376,7 +376,7 @@ impl Controller { project_id: &ProjectId, target_branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { self.inner(project_id) .await .move_commit(project_id, target_branch_id, commit_oid) @@ -420,7 +420,7 @@ impl ControllerInner { message: &str, ownership: Option<&BranchOwnershipClaims>, run_hooks: bool, - ) -> Result { + ) -> Result { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -453,7 +453,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_name: &git::RemoteRefname, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -474,7 +474,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user().context("failed to get user")?; @@ -493,7 +493,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_ids: Vec, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user().context("failed to get user")?; @@ -547,7 +547,7 @@ impl ControllerInner { pub async fn list_virtual_branches( &self, project_id: &ProjectId, - ) -> Result<(Vec, bool, Vec), Error2> { + ) -> Result<(Vec, bool, Vec), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -559,7 +559,7 @@ impl ControllerInner { &self, project_id: &ProjectId, create: &super::branch::BranchCreateRequest, - ) -> Result { + ) -> Result { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -573,7 +573,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch: &git::Refname, - ) -> Result { + ) -> Result { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -601,7 +601,7 @@ impl ControllerInner { pub fn get_base_branch_data( &self, project_id: &ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -621,7 +621,7 @@ impl ControllerInner { &self, project_id: &ProjectId, commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let use_context = project_repository @@ -641,7 +641,7 @@ impl ControllerInner { &self, project_id: &ProjectId, target_branch: &git::RemoteRefname, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let user = self.users.get_user()?; let project_repository = project_repository::Repository::open(&project)?; @@ -663,7 +663,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -689,7 +689,7 @@ impl ControllerInner { }) } - pub async fn update_base_branch(&self, project_id: &ProjectId) -> Result<(), Error2> { + pub async fn update_base_branch(&self, project_id: &ProjectId) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -718,7 +718,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_update: super::branch::BranchUpdateRequest, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -731,7 +731,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -744,7 +744,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -774,7 +774,7 @@ impl ControllerInner { &self, project_id: &ProjectId, ownership: &BranchOwnershipClaims, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -787,7 +787,7 @@ impl ControllerInner { &self, project_id: &ProjectId, ownership: &Vec, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |_, project_repository, _| { @@ -800,7 +800,7 @@ impl ControllerInner { project_id: &ProjectId, branch_id: &BranchId, ownership: &BranchOwnershipClaims, - ) -> Result { + ) -> Result { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -814,7 +814,7 @@ impl ControllerInner { project_id: &ProjectId, branch_id: &BranchId, target_commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -832,7 +832,7 @@ impl ControllerInner { &self, project_id: &ProjectId, branch_id: &BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -848,7 +848,7 @@ impl ControllerInner { branch_id: &BranchId, with_force: bool, askpass: Option<(AskpassBroker, Option)>, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; let helper = self.helper.clone(); let project_id = *project_id; @@ -864,7 +864,7 @@ impl ControllerInner { )?) })? .await - .map_err(Error2::from_err)? + .map_err(Error::from_err)? } pub async fn cherry_pick( @@ -872,7 +872,7 @@ impl ControllerInner { project_id: &ProjectId, branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -884,7 +884,7 @@ impl ControllerInner { pub fn list_remote_branches( &self, project_id: &ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -904,7 +904,7 @@ impl ControllerInner { &self, project_id: &ProjectId, refname: &git::Refname, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -926,7 +926,7 @@ impl ControllerInner { project_id: &ProjectId, branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { @@ -941,7 +941,7 @@ impl ControllerInner { branch_id: &BranchId, commit_oid: git::Oid, message: &str, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, _| { super::update_commit_message( @@ -959,7 +959,7 @@ impl ControllerInner { &self, project_id: &ProjectId, askpass: Option<(AskpassBroker, String)>, - ) -> Result { + ) -> Result { let project = self.projects.get(project_id)?; let mut project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -1015,7 +1015,7 @@ impl ControllerInner { project_id: &ProjectId, target_branch_id: &BranchId, commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let _permit = self.semaphore.acquire().await; self.with_verify_branch(project_id, |gb_repository, project_repository, user| { @@ -1050,8 +1050,8 @@ impl ControllerInner { &gb_repository::Repository, &project_repository::Repository, Option<&users::User>, - ) -> Result, - ) -> Result { + ) -> Result, + ) -> Result { let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users.get_user()?; @@ -1072,10 +1072,10 @@ impl ControllerInner { &gb_repository::Repository, &project_repository::Repository, Option<&users::User>, - ) -> Result + ) -> Result + Send + 'static, - ) -> Result>, Error2> { + ) -> Result>, Error> { let local_data_dir = self.local_data_dir.clone(); let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(&project)?; diff --git a/crates/gitbutler-core/src/virtual_branches/errors.rs b/crates/gitbutler-core/src/virtual_branches/errors.rs index 5f203e93e..1bf1bb9a1 100644 --- a/crates/gitbutler-core/src/virtual_branches/errors.rs +++ b/crates/gitbutler-core/src/virtual_branches/errors.rs @@ -1,9 +1,7 @@ use super::{branch::BranchOwnershipClaims, BranchId, GITBUTLER_INTEGRATION_REFERENCE}; use crate::error::{AnyhowContextExt, Code, Context, ErrorWithContext}; use crate::{ - error, - error::Error, - git, + error, git, project_repository::{self, RemoteError}, projects::ProjectId, }; @@ -20,36 +18,6 @@ pub enum VerifyError { Other(#[from] anyhow::Error), } -impl From for crate::error::Error { - fn from(value: VerifyError) -> Self { - match value { - VerifyError::DetachedHead => crate::error::Error::UserError { - code: crate::error::Code::ProjectHead, - message: format!( - "Project in detached head state. Please checkout {0} to continue.", - GITBUTLER_INTEGRATION_REFERENCE.branch() - ), - }, - VerifyError::InvalidHead(head) => crate::error::Error::UserError { - code: crate::error::Code::ProjectHead, - message: format!( - "Project is on {}. Please checkout {} to continue.", - head, - GITBUTLER_INTEGRATION_REFERENCE.branch() - ), - }, - VerifyError::NoIntegrationCommit => crate::error::Error::UserError { - code: crate::error::Code::ProjectHead, - message: "GibButler's integration commit not found on head.".to_string(), - }, - VerifyError::Other(error) => { - tracing::error!(?error); - crate::error::Error::Unknown - } - } - } -} - impl ErrorWithContext for VerifyError { fn context(&self) -> Option { Some(match self { @@ -77,35 +45,6 @@ impl ErrorWithContext for VerifyError { } } -#[derive(Debug, thiserror::Error)] -pub enum DeleteBranchError { - #[error(transparent)] - UnapplyBranch(#[from] UnapplyBranchError), - #[error(transparent)] - Other(#[from] anyhow::Error), -} - -impl From for Error { - fn from(value: DeleteBranchError) -> Self { - match value { - DeleteBranchError::UnapplyBranch(error) => error.into(), - DeleteBranchError::Other(error) => { - tracing::error!(?error, "delete branch error"); - Error::Unknown - } - } - } -} - -impl ErrorWithContext for DeleteBranchError { - fn context(&self) -> Option { - match self { - DeleteBranchError::UnapplyBranch(error) => error.context(), - DeleteBranchError::Other(error) => error.custom_context(), - } - } -} - #[derive(Debug, thiserror::Error)] pub enum ResetBranchError { #[error("commit {0} not in the branch")] @@ -118,23 +57,6 @@ pub enum ResetBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: ResetBranchError) -> Self { - match value { - ResetBranchError::BranchNotFound(error) => error.into(), - ResetBranchError::DefaultTargetNotSet(error) => error.into(), - ResetBranchError::CommitNotFoundInBranch(oid) => Error::UserError { - code: crate::error::Code::Branches, - message: format!("commit {} not found", oid), - }, - ResetBranchError::Other(error) => { - tracing::error!(?error, "reset branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for ResetBranchError { fn context(&self) -> Option { Some(match self { @@ -162,24 +84,6 @@ pub enum ApplyBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: ApplyBranchError) -> Self { - match value { - ApplyBranchError::DefaultTargetNotSet(error) => error.into(), - ApplyBranchError::Conflict(error) => error.into(), - ApplyBranchError::BranchNotFound(error) => error.into(), - ApplyBranchError::BranchConflicts(id) => Error::UserError { - message: format!("Branch {} is in a conflicing state", id), - code: crate::error::Code::Branches, - }, - ApplyBranchError::Other(error) => { - tracing::error!(?error, "apply branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for ApplyBranchError { fn context(&self) -> Option { Some(match self { @@ -205,19 +109,6 @@ pub enum UnapplyOwnershipError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: UnapplyOwnershipError) -> Self { - match value { - UnapplyOwnershipError::DefaultTargetNotSet(error) => error.into(), - UnapplyOwnershipError::Conflict(error) => error.into(), - UnapplyOwnershipError::Other(error) => { - tracing::error!(?error, "unapply ownership error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for UnapplyOwnershipError { fn context(&self) -> Option { Some(match self { @@ -238,19 +129,6 @@ pub enum UnapplyBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: UnapplyBranchError) -> Self { - match value { - UnapplyBranchError::DefaultTargetNotSet(error) => error.into(), - UnapplyBranchError::BranchNotFound(error) => error.into(), - UnapplyBranchError::Other(error) => { - tracing::error!(?error, "unapply branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for UnapplyBranchError { fn context(&self) -> Option { Some(match self { @@ -269,18 +147,6 @@ pub enum ListVirtualBranchesError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: ListVirtualBranchesError) -> Self { - match value { - ListVirtualBranchesError::DefaultTargetNotSet(error) => error.into(), - ListVirtualBranchesError::Other(error) => { - tracing::error!(?error, "list virtual branches error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for ListVirtualBranchesError { fn context(&self) -> Option { match self { @@ -298,18 +164,6 @@ pub enum CreateVirtualBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: CreateVirtualBranchError) -> Self { - match value { - CreateVirtualBranchError::DefaultTargetNotSet(error) => error.into(), - CreateVirtualBranchError::Other(error) => { - tracing::error!(?error, "create virtual branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for CreateVirtualBranchError { fn context(&self) -> Option { match self { @@ -329,19 +183,6 @@ pub enum MergeVirtualBranchUpstreamError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: MergeVirtualBranchUpstreamError) -> Self { - match value { - MergeVirtualBranchUpstreamError::BranchNotFound(error) => error.into(), - MergeVirtualBranchUpstreamError::Conflict(error) => error.into(), - MergeVirtualBranchUpstreamError::Other(error) => { - tracing::error!(?error, "merge virtual branch upstream error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for MergeVirtualBranchUpstreamError { fn context(&self) -> Option { Some(match self { @@ -368,28 +209,6 @@ pub enum CommitError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: CommitError) -> Self { - match value { - CommitError::BranchNotFound(error) => error.into(), - CommitError::DefaultTargetNotSet(error) => error.into(), - CommitError::Conflicted(error) => error.into(), - CommitError::CommitHookRejected(error) => Error::UserError { - code: crate::error::Code::PreCommitHook, - message: error, - }, - CommitError::CommitMsgHookRejected(error) => Error::UserError { - code: crate::error::Code::CommitMsgHook, - message: error, - }, - CommitError::Other(error) => { - tracing::error!(?error, "commit error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for CommitError { fn context(&self) -> Option { Some(match self { @@ -419,20 +238,6 @@ pub enum PushError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: PushError) -> Self { - match value { - PushError::Remote(error) => error.into(), - PushError::BranchNotFound(error) => error.into(), - PushError::DefaultTargetNotSet(error) => error.into(), - PushError::Other(error) => { - tracing::error!(?error, "push error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for PushError { fn context(&self) -> Option { Some(match self { @@ -454,22 +259,6 @@ pub enum IsRemoteBranchMergableError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: IsRemoteBranchMergableError) -> Self { - match value { - IsRemoteBranchMergableError::BranchNotFound(name) => Error::UserError { - message: format!("Remote branch {} not found", name), - code: crate::error::Code::Branches, - }, - IsRemoteBranchMergableError::DefaultTargetNotSet(error) => error.into(), - IsRemoteBranchMergableError::Other(error) => { - tracing::error!(?error, "is remote branch mergable error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for IsRemoteBranchMergableError { fn context(&self) -> Option { Some(match self { @@ -492,19 +281,6 @@ pub enum IsVirtualBranchMergeable { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: IsVirtualBranchMergeable) -> Self { - match value { - IsVirtualBranchMergeable::BranchNotFound(error) => error.into(), - IsVirtualBranchMergeable::DefaultTargetNotSet(error) => error.into(), - IsVirtualBranchMergeable::Other(error) => { - tracing::error!(?error, "is remote branch mergable error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for IsVirtualBranchMergeable { fn context(&self) -> Option { Some(match self { @@ -520,15 +296,6 @@ pub struct ForcePushNotAllowed { pub project_id: ProjectId, } -impl From for Error { - fn from(_value: ForcePushNotAllowed) -> Self { - Error::UserError { - code: crate::error::Code::Branches, - message: "Action will lead to force pushing, which is not allowed for this".to_string(), - } - } -} - impl ForcePushNotAllowed { fn to_context(&self) -> error::Context { error::Context::new_static( @@ -556,29 +323,6 @@ pub enum AmendError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: AmendError) -> Self { - match value { - AmendError::ForcePushNotAllowed(error) => error.into(), - AmendError::Conflict(error) => error.into(), - AmendError::BranchNotFound(error) => error.into(), - AmendError::BranchHasNoCommits => Error::UserError { - message: "Branch has no commits - there is nothing to amend to".to_string(), - code: crate::error::Code::Branches, - }, - AmendError::DefaultTargetNotSet(error) => error.into(), - AmendError::TargetOwnerhshipNotFound(_) => Error::UserError { - message: "target ownership not found".to_string(), - code: crate::error::Code::Branches, - }, - AmendError::Other(error) => { - tracing::error!(?error, "amend error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for AmendError { fn context(&self) -> Option { Some(match self { @@ -610,26 +354,6 @@ pub enum CherryPickError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: CherryPickError) -> Self { - match value { - CherryPickError::NotApplied => Error::UserError { - message: "can not cherry pick non applied branch".to_string(), - code: crate::error::Code::Branches, - }, - CherryPickError::Conflict(error) => error.into(), - CherryPickError::CommitNotFound(oid) => Error::UserError { - message: format!("commit {oid} not found"), - code: crate::error::Code::Branches, - }, - CherryPickError::Other(error) => { - tracing::error!(?error, "cherry pick error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for CherryPickError { fn context(&self) -> Option { Some(match self { @@ -663,29 +387,6 @@ pub enum SquashError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: SquashError) -> Self { - match value { - SquashError::ForcePushNotAllowed(error) => error.into(), - SquashError::DefaultTargetNotSet(error) => error.into(), - SquashError::BranchNotFound(error) => error.into(), - SquashError::Conflict(error) => error.into(), - SquashError::CantSquashRootCommit => Error::UserError { - message: "can not squash root branch commit".to_string(), - code: crate::error::Code::Branches, - }, - SquashError::CommitNotFound(oid) => Error::UserError { - message: format!("commit {oid} not found"), - code: crate::error::Code::Branches, - }, - SquashError::Other(error) => { - tracing::error!(?error, "squash error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for SquashError { fn context(&self) -> Option { Some(match self { @@ -715,19 +416,6 @@ pub enum FetchFromTargetError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: FetchFromTargetError) -> Self { - match value { - FetchFromTargetError::DefaultTargetNotSet(error) => error.into(), - FetchFromTargetError::Remote(error) => error.into(), - FetchFromTargetError::Other(error) => { - tracing::error!(?error, "fetch from target error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for FetchFromTargetError { fn context(&self) -> Option { match self { @@ -756,29 +444,6 @@ pub enum UpdateCommitMessageError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: UpdateCommitMessageError) -> Self { - match value { - UpdateCommitMessageError::ForcePushNotAllowed(error) => error.into(), - UpdateCommitMessageError::EmptyMessage => Error::UserError { - message: "Commit message can not be empty".to_string(), - code: crate::error::Code::Branches, - }, - UpdateCommitMessageError::DefaultTargetNotSet(error) => error.into(), - UpdateCommitMessageError::CommitNotFound(oid) => Error::UserError { - message: format!("Commit {} not found", oid), - code: crate::error::Code::Branches, - }, - UpdateCommitMessageError::BranchNotFound(error) => error.into(), - UpdateCommitMessageError::Conflict(error) => error.into(), - UpdateCommitMessageError::Other(error) => { - tracing::error!(?error, "update commit message error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for UpdateCommitMessageError { fn context(&self) -> Option { Some(match self { @@ -807,25 +472,6 @@ pub enum SetBaseBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: SetBaseBranchError) -> Self { - match value { - SetBaseBranchError::DirtyWorkingDirectory => Error::UserError { - message: "Current HEAD is dirty.".to_string(), - code: crate::error::Code::ProjectConflict, - }, - SetBaseBranchError::BranchNotFound(name) => Error::UserError { - message: format!("remote branch '{}' not found", name), - code: crate::error::Code::Branches, - }, - SetBaseBranchError::Other(error) => { - tracing::error!(?error, "set base branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for SetBaseBranchError { fn context(&self) -> Option { Some(match self { @@ -851,19 +497,6 @@ pub enum UpdateBaseBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: UpdateBaseBranchError) -> Self { - match value { - UpdateBaseBranchError::Conflict(error) => error.into(), - UpdateBaseBranchError::DefaultTargetNotSet(error) => error.into(), - UpdateBaseBranchError::Other(error) => { - tracing::error!(?error, "update base branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for UpdateBaseBranchError { fn context(&self) -> Option { Some(match self { @@ -890,28 +523,6 @@ pub enum MoveCommitError { Other(#[from] anyhow::Error), } -impl From for crate::error::Error { - fn from(value: MoveCommitError) -> Self { - match value { - MoveCommitError::SourceLocked => Error::UserError { - message: "Source branch contains hunks locked to the target commit".to_string(), - code: crate::error::Code::Branches, - }, - MoveCommitError::Conflicted(error) => error.into(), - MoveCommitError::DefaultTargetNotSet(error) => error.into(), - MoveCommitError::BranchNotFound(error) => error.into(), - MoveCommitError::CommitNotFound(oid) => Error::UserError { - message: format!("Commit {} not found", oid), - code: crate::error::Code::Branches, - }, - MoveCommitError::Other(error) => { - tracing::error!(?error, "move commit to vbranch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for MoveCommitError { fn context(&self) -> Option { Some(match self { @@ -944,29 +555,6 @@ pub enum CreateVirtualBranchFromBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: CreateVirtualBranchFromBranchError) -> Self { - match value { - CreateVirtualBranchFromBranchError::ApplyBranch(error) => error.into(), - CreateVirtualBranchFromBranchError::CantMakeBranchFromDefaultTarget => { - Error::UserError { - message: "Can not create a branch from default target".to_string(), - code: crate::error::Code::Branches, - } - } - CreateVirtualBranchFromBranchError::DefaultTargetNotSet(error) => error.into(), - CreateVirtualBranchFromBranchError::BranchNotFound(name) => Error::UserError { - message: format!("Branch {} not found", name), - code: crate::error::Code::Branches, - }, - CreateVirtualBranchFromBranchError::Other(error) => { - tracing::error!(?error, "create virtual branch from branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for CreateVirtualBranchFromBranchError { fn context(&self) -> Option { Some(match self { @@ -991,15 +579,6 @@ pub struct ProjectConflict { pub project_id: ProjectId, } -impl From for Error { - fn from(value: ProjectConflict) -> Self { - Error::UserError { - code: crate::error::Code::ProjectConflict, - message: format!("project {} is in a conflicted state", value.project_id), - } - } -} - impl ProjectConflict { fn to_context(&self) -> error::Context { error::Context::new( @@ -1014,18 +593,6 @@ pub struct DefaultTargetNotSet { pub project_id: ProjectId, } -impl From for Error { - fn from(value: DefaultTargetNotSet) -> Self { - Error::UserError { - code: crate::error::Code::ProjectConflict, - message: format!( - "project {} does not have a default target set", - value.project_id - ), - } - } -} - impl DefaultTargetNotSet { fn to_context(&self) -> error::Context { error::Context::new( @@ -1044,15 +611,6 @@ pub struct BranchNotFound { pub branch_id: BranchId, } -impl From for Error { - fn from(value: BranchNotFound) -> Self { - Error::UserError { - code: crate::error::Code::Branches, - message: format!("branch {} not found", value.branch_id), - } - } -} - impl BranchNotFound { fn to_context(&self) -> error::Context { error::Context::new( @@ -1072,19 +630,6 @@ pub enum UpdateBranchError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: UpdateBranchError) -> Self { - match value { - UpdateBranchError::DefaultTargetNotSet(error) => error.into(), - UpdateBranchError::BranchNotFound(error) => error.into(), - UpdateBranchError::Other(error) => { - tracing::error!(?error, "update branch error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for UpdateBranchError { fn context(&self) -> Option { Some(match self { @@ -1103,21 +648,6 @@ pub enum ListRemoteCommitFilesError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: ListRemoteCommitFilesError) -> Self { - match value { - ListRemoteCommitFilesError::CommitNotFound(oid) => Error::UserError { - message: format!("Commit {} not found", oid), - code: crate::error::Code::Branches, - }, - ListRemoteCommitFilesError::Other(error) => { - tracing::error!(?error, "list remote commit files error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for ListRemoteCommitFilesError { fn context(&self) -> Option { match self { @@ -1137,18 +667,6 @@ pub enum ListRemoteBranchesError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: ListRemoteBranchesError) -> Self { - match value { - ListRemoteBranchesError::DefaultTargetNotSet(error) => error.into(), - ListRemoteBranchesError::Other(error) => { - tracing::error!(?error, "list remote branches error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for ListRemoteBranchesError { fn context(&self) -> Option { match self { @@ -1166,18 +684,6 @@ pub enum GetRemoteBranchDataError { Other(#[from] anyhow::Error), } -impl From for Error { - fn from(value: GetRemoteBranchDataError) -> Self { - match value { - GetRemoteBranchDataError::DefaultTargetNotSet(error) => error.into(), - GetRemoteBranchDataError::Other(error) => { - tracing::error!(?error, "get remote branch data error"); - Error::Unknown - } - } - } -} - impl ErrorWithContext for GetRemoteBranchDataError { fn context(&self) -> Option { match self { diff --git a/crates/gitbutler-core/src/virtual_branches/virtual.rs b/crates/gitbutler-core/src/virtual_branches/virtual.rs index d0880cb24..5e5a3a917 100644 --- a/crates/gitbutler-core/src/virtual_branches/virtual.rs +++ b/crates/gitbutler-core/src/virtual_branches/virtual.rs @@ -7,7 +7,7 @@ use std::{ time, vec, }; -use anyhow::{bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use bstr::ByteSlice; use diffy::{apply, Patch}; use git2_hooks::HookResult; @@ -21,6 +21,7 @@ use super::{ branch_to_remote_branch, context, errors, target, Iterator, RemoteBranch, VirtualBranchesHandle, }; +use crate::error::Error; use crate::{ askpass::AskpassBroker, dedup::{dedup, dedup_fmt}, @@ -37,12 +38,6 @@ use crate::{ type AppliedStatuses = Vec<(branch::Branch, HashMap>)>; -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("path contains invalid utf-8 characters: {0}")] - InvalidUnicodePath(PathBuf), -} - // this struct is a mapping to the view `Branch` type in Typescript // found in src-tauri/src/routes/repo/[project_id]/types.ts // it holds a materialized view for presentation purposes of the Branch struct in Rust @@ -1839,7 +1834,7 @@ pub fn delete_branch( gb_repository: &gb_repository::Repository, project_repository: &project_repository::Repository, branch_id: &BranchId, -) -> Result<(), errors::DeleteBranchError> { +) -> Result<(), Error> { let current_session = gb_repository .get_or_create_current_session() .context("failed to get or create currnt session")?; @@ -2503,7 +2498,9 @@ pub fn write_tree_onto_tree( let blob_oid = git_repository.blob( link_target .to_str() - .ok_or_else(|| Error::InvalidUnicodePath(link_target.into()))? + .ok_or_else(|| { + anyhow!("path contains invalid utf-8 characters: {link_target:?}") + })? .as_bytes(), )?; builder.upsert(rel_path, blob_oid, filemode); diff --git a/crates/gitbutler-core/src/zip/controller.rs b/crates/gitbutler-core/src/zip/controller.rs index 4ea6afdd8..790c27565 100644 --- a/crates/gitbutler-core/src/zip/controller.rs +++ b/crates/gitbutler-core/src/zip/controller.rs @@ -1,4 +1,4 @@ -use crate::error::Error2; +use crate::error::Error; use std::path; use super::Zipper; @@ -28,12 +28,12 @@ impl Controller { } } - pub fn archive(&self, project_id: &ProjectId) -> Result { + pub fn archive(&self, project_id: &ProjectId) -> Result { let project = self.projects_controller.get(project_id)?; self.zipper.zip(project.path).map_err(Into::into) } - pub fn data_archive(&self, project_id: &ProjectId) -> Result { + pub fn data_archive(&self, project_id: &ProjectId) -> Result { let project = self.projects_controller.get(project_id)?; self.zipper .zip( diff --git a/gitbutler-app/src/app.rs b/gitbutler-app/src/app.rs index 32501180a..433ec65e9 100644 --- a/gitbutler-app/src/app.rs +++ b/gitbutler-app/src/app.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, path}; use anyhow::{Context, Result}; -use gitbutler_core::error::Error2 as CoreError; +use gitbutler_core::error::Error as CoreError; use gitbutler_core::{ askpass::AskpassBroker, gb_repository, git, @@ -13,7 +13,7 @@ use gitbutler_core::{ virtual_branches::BranchId, }; -use crate::error::Error2; +use crate::error::Error; use crate::watcher; #[derive(Clone)] @@ -69,7 +69,7 @@ impl App { project_id: &ProjectId, session_id: &SessionId, paths: Option<&[&path::Path]>, - ) -> Result, Error2> { + ) -> Result, Error> { let session = self .sessions_database .get_by_project_id_id(project_id, session_id) @@ -79,9 +79,9 @@ impl App { let project = self .projects .get(project_id) - .map_err(Error2::from_error_with_context)?; + .map_err(Error::from_error_with_context)?; let project_repository = project_repository::Repository::open(&project) - .map_err(Error2::from_error_with_context)?; + .map_err(Error::from_error_with_context)?; let gb_repo = gb_repository::Repository::open( &self.local_data_dir, &project_repository, diff --git a/gitbutler-app/src/commands.rs b/gitbutler-app/src/commands.rs index 8b119357f..1527bcb8e 100644 --- a/gitbutler-app/src/commands.rs +++ b/gitbutler-app/src/commands.rs @@ -11,7 +11,7 @@ use gitbutler_core::{ use tauri::Manager; use tracing::instrument; -use crate::error::Error2; +use crate::error::Error; use crate::{app, watcher}; #[tauri::command(async)] @@ -21,7 +21,7 @@ pub async fn list_session_files( project_id: ProjectId, session_id: SessionId, paths: Option>, -) -> Result, Error2> { +) -> Result, Error> { let app = handle.state::(); let files = app.list_session_files(&project_id, &session_id, paths.as_deref())?; Ok(files) @@ -32,7 +32,7 @@ pub async fn list_session_files( pub async fn git_remote_branches( handle: tauri::AppHandle, project_id: ProjectId, -) -> Result, Error2> { +) -> Result, Error> { let app = handle.state::(); let branches = app.git_remote_branches(&project_id)?; Ok(branches) @@ -45,7 +45,7 @@ pub async fn git_test_push( project_id: ProjectId, remote_name: &str, branch_name: &str, -) -> Result<(), Error2> { +) -> Result<(), Error> { let app = handle.state::(); let helper = handle.state::(); let askpass_broker = handle @@ -68,7 +68,7 @@ pub async fn git_test_fetch( project_id: ProjectId, remote_name: &str, action: Option, -) -> Result<(), Error2> { +) -> Result<(), Error> { let app = handle.state::(); let helper = handle.state::(); let askpass_broker = handle @@ -88,14 +88,14 @@ pub async fn git_test_fetch( pub async fn git_index_size( handle: tauri::AppHandle, project_id: ProjectId, -) -> Result { +) -> Result { let app = handle.state::(); Ok(app.git_index_size(&project_id).expect("git index size")) } #[tauri::command(async)] #[instrument(skip(handle))] -pub async fn git_head(handle: tauri::AppHandle, project_id: ProjectId) -> Result { +pub async fn git_head(handle: tauri::AppHandle, project_id: ProjectId) -> Result { let app = handle.state::(); let head = app.git_head(&project_id)?; Ok(head) @@ -103,7 +103,7 @@ pub async fn git_head(handle: tauri::AppHandle, project_id: ProjectId) -> Result #[tauri::command(async)] #[instrument(skip(handle))] -pub async fn delete_all_data(handle: tauri::AppHandle) -> Result<(), Error2> { +pub async fn delete_all_data(handle: tauri::AppHandle) -> Result<(), Error> { let app = handle.state::(); app.delete_all_data().await?; Ok(()) @@ -115,7 +115,7 @@ pub async fn mark_resolved( handle: tauri::AppHandle, project_id: ProjectId, path: &str, -) -> Result<(), Error2> { +) -> Result<(), Error> { let app = handle.state::(); app.mark_resolved(&project_id, path)?; Ok(()) @@ -127,7 +127,7 @@ pub async fn git_set_global_config( _handle: tauri::AppHandle, key: &str, value: &str, -) -> Result { +) -> Result { let result = app::App::git_set_global_config(key, value)?; Ok(result) } @@ -137,14 +137,14 @@ pub async fn git_set_global_config( pub async fn git_get_global_config( _handle: tauri::AppHandle, key: &str, -) -> Result, Error2> { +) -> Result, Error> { let result = app::App::git_get_global_config(key)?; Ok(result) } #[tauri::command(async)] #[instrument(skip(handle))] -pub async fn project_flush_and_push(handle: tauri::AppHandle, id: ProjectId) -> Result<(), Error2> { +pub async fn project_flush_and_push(handle: tauri::AppHandle, id: ProjectId) -> Result<(), Error> { let users = handle.state::().inner().clone(); let projects = handle.state::().inner().clone(); let local_data_dir = handle @@ -155,7 +155,7 @@ pub async fn project_flush_and_push(handle: tauri::AppHandle, id: ProjectId) -> let project = projects.get(&id).context("failed to get project")?; let user = users.get_user()?; let project_repository = - project_repository::Repository::open(&project).map_err(Error2::from_error_with_context)?; + project_repository::Repository::open(&project).map_err(Error::from_error_with_context)?; let gb_repo = gb_repository::Repository::open(&local_data_dir, &project_repository, user.as_ref()) .context("failed to open repository")?; diff --git a/gitbutler-app/src/deltas.rs b/gitbutler-app/src/deltas.rs index 7357d5ba4..f864d059b 100644 --- a/gitbutler-app/src/deltas.rs +++ b/gitbutler-app/src/deltas.rs @@ -4,10 +4,11 @@ pub mod commands { use gitbutler_core::deltas::{Controller, Delta}; use gitbutler_core::error; + use gitbutler_core::error::Code; use tauri::{AppHandle, Manager}; use tracing::instrument; - use crate::error::{Code, Error2}; + use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] @@ -16,7 +17,7 @@ pub mod commands { project_id: &str, session_id: &str, paths: Option>, - ) -> Result>, Error2> { + ) -> Result>, Error> { let session_id = session_id.parse().context(error::Context::new_static( Code::Validation, "Malformed session id", diff --git a/gitbutler-app/src/error.rs b/gitbutler-app/src/error.rs index a4933cf5c..ae5f36f8e 100644 --- a/gitbutler-app/src/error.rs +++ b/gitbutler-app/src/error.rs @@ -1,9 +1,6 @@ -pub(crate) use frontend::Error2; -pub use gitbutler_core::error::Code; -pub(crate) use legacy::Error; +pub(crate) use frontend::Error; mod frontend { - use anyhow::Error; use gitbutler_core::error::{into_anyhow, AnyhowContextExt, ErrorWithContext}; use serde::{ser::SerializeMap, Serialize}; use std::borrow::Cow; @@ -11,21 +8,21 @@ mod frontend { /// An error type for serialization, dynamically extracting context information during serialization, /// meant for consumption by the frontend. #[derive(Debug)] - pub struct Error2(anyhow::Error); + pub struct Error(anyhow::Error); - impl From for Error2 { - fn from(value: Error) -> Self { + impl From for Error { + fn from(value: anyhow::Error) -> Self { Self(value) } } - impl From for Error2 { - fn from(value: gitbutler_core::error::Error2) -> Self { + impl From for Error { + fn from(value: gitbutler_core::error::Error) -> Self { Self(value.into()) } } - impl Error2 { + impl Error { /// Convert an error with context to our type. /// /// Note that this is only needed as trait specialization isn't working well enough yet. @@ -34,7 +31,7 @@ mod frontend { } } - impl Serialize for Error2 { + impl Serialize for Error { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -61,7 +58,7 @@ mod frontend { use gitbutler_core::error::{Code, Context}; fn json(err: anyhow::Error) -> String { - serde_json::to_string(&Error2(err)).unwrap() + serde_json::to_string(&Error(err)).unwrap() } #[test] @@ -130,62 +127,3 @@ mod frontend { } } } - -//#[deprecated( -// note = "the types in the error::legacy::* module are deprecated; use error::gb::Error and error::gb::Result instead" -//)] -mod legacy { - use gitbutler_core::error::Code; - use gitbutler_core::project_repository; - use serde::{ser::SerializeMap, Serialize}; - - #[derive(Debug, thiserror::Error)] - pub enum Error { - #[error("[{code}]: {message}")] - UserError { code: Code, message: String }, - #[error("[errors.unknown]: Something went wrong")] - Unknown, - } - - impl Serialize for Error { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - let (code, message) = match self { - Error::UserError { code, message } => (code.to_string(), message.to_string()), - Error::Unknown => ( - Code::Unknown.to_string(), - "Something went wrong".to_string(), - ), - }; - - let mut map = serializer.serialize_map(Some(2))?; - map.serialize_entry("code", &code)?; - map.serialize_entry("message", &message)?; - map.end() - } - } - - impl From for Error { - fn from(error: anyhow::Error) -> Self { - tracing::error!(?error); - Error::Unknown - } - } - - impl From for Error { - fn from(value: project_repository::OpenError) -> Self { - match value { - project_repository::OpenError::NotFound(path) => Error::UserError { - code: Code::Projects, - message: format!("{} not found", path.display()), - }, - project_repository::OpenError::Other(error) => { - tracing::error!(?error); - Error::Unknown - } - } - } - } -} diff --git a/gitbutler-app/src/github.rs b/gitbutler-app/src/github.rs index 69aba9aae..1a1041780 100644 --- a/gitbutler-app/src/github.rs +++ b/gitbutler-app/src/github.rs @@ -5,7 +5,7 @@ pub mod commands { use serde::{Deserialize, Serialize}; use tracing::instrument; - use crate::error::Error2; + use crate::error::Error; const GITHUB_CLIENT_ID: &str = "cd51880daa675d9e6452"; @@ -17,7 +17,7 @@ pub mod commands { #[tauri::command(async)] #[instrument] - pub async fn init_device_oauth() -> Result { + pub async fn init_device_oauth() -> Result { let mut req_body = HashMap::new(); req_body.insert("client_id", GITHUB_CLIENT_ID); req_body.insert("scope", "repo"); @@ -46,7 +46,7 @@ pub mod commands { #[tauri::command(async)] #[instrument] - pub async fn check_auth_status(device_code: &str) -> Result { + pub async fn check_auth_status(device_code: &str) -> Result { #[derive(Debug, Deserialize, Serialize, Clone, Default)] struct AccessTokenContainer { access_token: String, diff --git a/gitbutler-app/src/keys.rs b/gitbutler-app/src/keys.rs index 26534ffe2..c96de1fb0 100644 --- a/gitbutler-app/src/keys.rs +++ b/gitbutler-app/src/keys.rs @@ -3,11 +3,11 @@ pub mod commands { use tauri::Manager; use tracing::instrument; - use crate::error::Error2; + use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn get_public_key(handle: tauri::AppHandle) -> Result { + pub async fn get_public_key(handle: tauri::AppHandle) -> Result { handle .state::() .get_or_create() diff --git a/gitbutler-app/src/menu.rs b/gitbutler-app/src/menu.rs index c49f7b0f1..e0f90c001 100644 --- a/gitbutler-app/src/menu.rs +++ b/gitbutler-app/src/menu.rs @@ -1,5 +1,6 @@ use anyhow::Context; use gitbutler_core::error; +use gitbutler_core::error::Code; use serde_json::json; use tauri::{ AppHandle, CustomMenuItem, Manager, Menu, MenuEntry, PackageInfo, Runtime, Submenu, @@ -7,7 +8,7 @@ use tauri::{ }; use tracing::instrument; -use crate::error::{Code, Error2}; +use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] @@ -15,7 +16,7 @@ pub async fn menu_item_set_enabled( handle: AppHandle, menu_item_id: &str, enabled: bool, -) -> Result<(), Error2> { +) -> Result<(), Error> { let window = handle .get_window("main") .expect("main window always present"); diff --git a/gitbutler-app/src/projects.rs b/gitbutler-app/src/projects.rs index a401c6749..5ff200f39 100644 --- a/gitbutler-app/src/projects.rs +++ b/gitbutler-app/src/projects.rs @@ -3,23 +3,24 @@ pub mod commands { use std::path; use gitbutler_core::error; + use gitbutler_core::error::Code; use gitbutler_core::projects::{self, controller::Controller}; use tauri::Manager; use tracing::instrument; - use crate::error::{Code, Error2}; + use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] pub async fn update_project( handle: tauri::AppHandle, project: projects::UpdateRequest, - ) -> Result { + ) -> Result { handle .state::() .update(&project) .await - .map_err(Error2::from_error_with_context) + .map_err(Error::from_error_with_context) } #[tauri::command(async)] @@ -27,11 +28,11 @@ pub mod commands { pub async fn add_project( handle: tauri::AppHandle, path: &path::Path, - ) -> Result { + ) -> Result { handle .state::() .add(path) - .map_err(Error2::from_error_with_context) + .map_err(Error::from_error_with_context) } #[tauri::command(async)] @@ -39,7 +40,7 @@ pub mod commands { pub async fn get_project( handle: tauri::AppHandle, id: &str, - ) -> Result { + ) -> Result { let id = id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", @@ -47,18 +48,18 @@ pub mod commands { handle .state::() .get(&id) - .map_err(Error2::from_error_with_context) + .map_err(Error::from_error_with_context) } #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn list_projects(handle: tauri::AppHandle) -> Result, Error2> { + pub async fn list_projects(handle: tauri::AppHandle) -> Result, Error> { handle.state::().list().map_err(Into::into) } #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn delete_project(handle: tauri::AppHandle, id: &str) -> Result<(), Error2> { + pub async fn delete_project(handle: tauri::AppHandle, id: &str) -> Result<(), Error> { let id = id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", @@ -76,7 +77,7 @@ pub mod commands { handle: tauri::AppHandle, id: &str, key: &str, - ) -> Result, Error2> { + ) -> Result, Error> { let id = id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", @@ -94,7 +95,7 @@ pub mod commands { id: &str, key: &str, value: &str, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let id = id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", diff --git a/gitbutler-app/src/sessions.rs b/gitbutler-app/src/sessions.rs index ad35fcba4..e7931189a 100644 --- a/gitbutler-app/src/sessions.rs +++ b/gitbutler-app/src/sessions.rs @@ -1,11 +1,12 @@ pub mod commands { use anyhow::Context; use gitbutler_core::error; + use gitbutler_core::error::Code; use gitbutler_core::sessions::{Controller, Session}; use tauri::{AppHandle, Manager}; use tracing::instrument; - use crate::error::{Code, Error2}; + use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] @@ -13,7 +14,7 @@ pub mod commands { handle: AppHandle, project_id: &str, earliest_timestamp_ms: Option, - ) -> Result, Error2> { + ) -> Result, Error> { let project_id = project_id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", diff --git a/gitbutler-app/src/users.rs b/gitbutler-app/src/users.rs index 2eb443384..39c79e6f3 100644 --- a/gitbutler-app/src/users.rs +++ b/gitbutler-app/src/users.rs @@ -6,12 +6,12 @@ pub mod commands { use tauri::{AppHandle, Manager}; use tracing::instrument; - use crate::error::Error2; + use crate::error::Error; use crate::sentry; #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn get_user(handle: AppHandle) -> Result, Error2> { + pub async fn get_user(handle: AppHandle) -> Result, Error> { let app = handle.state::(); let proxy = handle.state::(); @@ -23,7 +23,7 @@ pub mod commands { #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn set_user(handle: AppHandle, user: User) -> Result { + pub async fn set_user(handle: AppHandle, user: User) -> Result { let app = handle.state::(); let proxy = handle.state::(); @@ -36,7 +36,7 @@ pub mod commands { #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn delete_user(handle: AppHandle) -> Result<(), Error2> { + pub async fn delete_user(handle: AppHandle) -> Result<(), Error> { let app = handle.state::(); app.delete_user()?; diff --git a/gitbutler-app/src/virtual_branches.rs b/gitbutler-app/src/virtual_branches.rs index 3f5ea0095..164b253af 100644 --- a/gitbutler-app/src/virtual_branches.rs +++ b/gitbutler-app/src/virtual_branches.rs @@ -1,5 +1,5 @@ pub mod commands { - use crate::error::Error2; + use crate::error::Error; use anyhow::Context; use gitbutler_core::{ askpass::AskpassBroker, @@ -27,7 +27,7 @@ pub mod commands { message: &str, ownership: Option, run_hooks: bool, - ) -> Result { + ) -> Result { let oid = handle .state::() .create_commit(&project_id, &branch, message, ownership.as_ref(), run_hooks) @@ -43,7 +43,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch_ids: Vec, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .save_vbranches_state(&project_id, branch_ids) @@ -56,7 +56,7 @@ pub mod commands { pub async fn list_virtual_branches( handle: AppHandle, project_id: ProjectId, - ) -> Result { + ) -> Result { let (branches, uses_diff_context, skipped_files) = handle .state::() .list_virtual_branches(&project_id) @@ -89,7 +89,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: branch::BranchCreateRequest, - ) -> Result { + ) -> Result { let branch_id = handle .state::() .create_virtual_branch(&project_id, &branch) @@ -104,7 +104,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: git::Refname, - ) -> Result { + ) -> Result { let branch_id = handle .state::() .create_virtual_branch_from_branch(&project_id, &branch) @@ -119,7 +119,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .merge_virtual_branch_upstream(&project_id, &branch) @@ -133,7 +133,7 @@ pub mod commands { pub async fn get_base_branch_data( handle: AppHandle, project_id: ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { if let Some(base_branch) = handle .state::() .get_base_branch_data(&project_id) @@ -153,7 +153,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: &str, - ) -> Result { + ) -> Result { let branch_name = format!("refs/remotes/{}", branch) .parse() .context("Invalid branch name")?; @@ -171,10 +171,7 @@ pub mod commands { #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn update_base_branch( - handle: AppHandle, - project_id: ProjectId, - ) -> Result<(), Error2> { + pub async fn update_base_branch(handle: AppHandle, project_id: ProjectId) -> Result<(), Error> { handle .state::() .update_base_branch(&project_id) @@ -189,7 +186,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: branch::BranchUpdateRequest, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .update_virtual_branch(&project_id, branch) @@ -205,7 +202,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch_id: BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .delete_virtual_branch(&project_id, &branch_id) @@ -220,7 +217,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .apply_virtual_branch(&project_id, &branch) @@ -235,7 +232,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .unapply_virtual_branch(&project_id, &branch) @@ -250,7 +247,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, ownership: BranchOwnershipClaims, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .unapply_ownership(&project_id, &ownership) @@ -265,7 +262,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, files: &str, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { // convert files to Vec let files = files .split('\n') @@ -286,7 +283,7 @@ pub mod commands { project_id: ProjectId, branch_id: BranchId, with_force: bool, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { let askpass_broker = handle.state::(); handle .state::() @@ -308,7 +305,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch_id: BranchId, - ) -> Result { + ) -> Result { handle .state::() .can_apply_virtual_branch(&project_id, &branch_id) @@ -322,7 +319,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, branch: git::RemoteRefname, - ) -> Result { + ) -> Result { Ok(handle .state::() .can_apply_remote_branch(&project_id, &branch) @@ -335,7 +332,7 @@ pub mod commands { handle: AppHandle, project_id: ProjectId, commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { handle .state::() .list_remote_commit_files(&project_id, commit_oid) @@ -350,7 +347,7 @@ pub mod commands { project_id: ProjectId, branch_id: BranchId, target_commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .reset_virtual_branch(&project_id, &branch_id, target_commit_oid) @@ -366,7 +363,7 @@ pub mod commands { project_id: ProjectId, branch_id: BranchId, target_commit_oid: git::Oid, - ) -> Result, Error2> { + ) -> Result, Error> { let oid = handle .state::() .cherry_pick(&project_id, &branch_id, target_commit_oid) @@ -382,7 +379,7 @@ pub mod commands { project_id: ProjectId, branch_id: BranchId, ownership: BranchOwnershipClaims, - ) -> Result { + ) -> Result { let oid = handle .state::() .amend(&project_id, &branch_id, &ownership) @@ -396,7 +393,7 @@ pub mod commands { pub async fn list_remote_branches( handle: tauri::AppHandle, project_id: ProjectId, - ) -> Result, Error2> { + ) -> Result, Error> { let branches = handle .state::() .list_remote_branches(&project_id) @@ -410,7 +407,7 @@ pub mod commands { handle: tauri::AppHandle, project_id: ProjectId, refname: git::Refname, - ) -> Result { + ) -> Result { let branch_data = handle .state::() .get_remote_branch_data(&project_id, &refname) @@ -429,7 +426,7 @@ pub mod commands { project_id: ProjectId, branch_id: BranchId, target_commit_oid: git::Oid, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .squash(&project_id, &branch_id, target_commit_oid) @@ -444,7 +441,7 @@ pub mod commands { handle: tauri::AppHandle, project_id: ProjectId, action: Option, - ) -> Result { + ) -> Result { let askpass_broker = handle.state::().inner().clone(); let base_branch = handle .state::() @@ -467,7 +464,7 @@ pub mod commands { project_id: ProjectId, commit_oid: git::Oid, target_branch_id: BranchId, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .move_commit(&project_id, &target_branch_id, commit_oid) @@ -484,7 +481,7 @@ pub mod commands { branch_id: BranchId, commit_oid: git::Oid, message: &str, - ) -> Result<(), Error2> { + ) -> Result<(), Error> { handle .state::() .update_commit_message(&project_id, &branch_id, commit_oid, message) diff --git a/gitbutler-app/src/zip.rs b/gitbutler-app/src/zip.rs index f0a8b7be3..9252df497 100644 --- a/gitbutler-app/src/zip.rs +++ b/gitbutler-app/src/zip.rs @@ -4,18 +4,19 @@ pub mod commands { use std::path; use gitbutler_core::error; + use gitbutler_core::error::Code; use gitbutler_core::zip::controller; use tauri::{AppHandle, Manager}; use tracing::instrument; - use crate::error::{Code, Error2}; + use crate::error::Error; #[tauri::command(async)] #[instrument(skip(handle))] pub async fn get_project_archive_path( handle: AppHandle, project_id: &str, - ) -> Result { + ) -> Result { let project_id = project_id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", @@ -31,7 +32,7 @@ pub mod commands { pub async fn get_project_data_archive_path( handle: AppHandle, project_id: &str, - ) -> Result { + ) -> Result { let project_id = project_id.parse().context(error::Context::new_static( Code::Validation, "Malformed project id", @@ -44,7 +45,7 @@ pub mod commands { #[tauri::command(async)] #[instrument(skip(handle))] - pub async fn get_logs_archive_path(handle: AppHandle) -> Result { + pub async fn get_logs_archive_path(handle: AppHandle) -> Result { handle .state::() .logs_archive()