mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-22 17:11:43 +03:00
handle errors
This commit is contained in:
parent
e89bd9bdf6
commit
ed9247f74c
@ -388,8 +388,11 @@ impl Repository {
|
||||
return Err(anyhow!("project does not exist"));
|
||||
}
|
||||
let project = project.unwrap();
|
||||
let project_repository = project_repository::Repository::open(&project)?;
|
||||
let session = self.create_current_session(&project_repository)?;
|
||||
let project_repository = project_repository::Repository::open(&project)
|
||||
.context("failed to open project repository")?;
|
||||
let session = self
|
||||
.create_current_session(&project_repository)
|
||||
.context("failed to create current session")?;
|
||||
Ok(session)
|
||||
}
|
||||
}
|
||||
@ -568,14 +571,14 @@ impl Repository {
|
||||
// calculate the commit as the merge-base between HEAD in project_repository and this target commit
|
||||
let head_oid = repo
|
||||
.head()
|
||||
.expect("Failed to get HEAD reference")
|
||||
.context("Failed to get HEAD reference")?
|
||||
.peel_to_commit()
|
||||
.expect("Failed to peel HEAD reference to commit")
|
||||
.context("Failed to peel HEAD reference to commit")?
|
||||
.id();
|
||||
|
||||
commit_oid = repo
|
||||
.merge_base(head_oid, commit_oid)
|
||||
.expect("Failed to calculate merge base");
|
||||
.context("Failed to calculate merge base")?;
|
||||
|
||||
println!("merge base: {:?}", commit_oid);
|
||||
}
|
||||
|
@ -446,9 +446,12 @@ async fn git_remote_branches(
|
||||
project_id: &str,
|
||||
) -> Result<Vec<String>, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let branches = app
|
||||
.git_remote_branches(project_id)
|
||||
.with_context(|| format!("failed to get git branches for project {}", project_id))?;
|
||||
let branches = app.git_remote_branches(project_id).with_context(|| {
|
||||
format!(
|
||||
"failed to get remote git branches for project {}",
|
||||
project_id
|
||||
)
|
||||
})?;
|
||||
Ok(branches)
|
||||
}
|
||||
|
||||
|
@ -593,10 +593,10 @@ pub fn list_virtual_branches(
|
||||
let mut branches: Vec<VirtualBranch> = Vec::new();
|
||||
let current_session = gb_repository
|
||||
.get_or_create_current_session()
|
||||
.expect("failed to get or create currnt session");
|
||||
.context("failed to get or create currnt session")?;
|
||||
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)
|
||||
.expect("failed to open current session reader");
|
||||
.context("failed to open current session reader")?;
|
||||
|
||||
let target_reader = target::Reader::new(¤t_session_reader);
|
||||
let default_target = match target_reader.read_default() {
|
||||
@ -1392,9 +1392,9 @@ pub fn get_status_by_branch(
|
||||
fn get_default_target(gb_repository: &gb_repository::Repository) -> Result<target::Target> {
|
||||
let current_session = gb_repository
|
||||
.get_or_create_current_session()
|
||||
.expect("failed to get or create currnt session");
|
||||
.context("failed to get or create currnt session")?;
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)
|
||||
.expect("failed to open current session reader");
|
||||
.context("failed to open current session reader")?;
|
||||
|
||||
let target_reader = target::Reader::new(¤t_session_reader);
|
||||
let default_target = match target_reader.read_default() {
|
||||
@ -1621,7 +1621,7 @@ fn write_tree(
|
||||
.to_object(git_repository)
|
||||
.unwrap()
|
||||
.peel_to_blob()
|
||||
.expect("failed to get blob");
|
||||
.context("failed to get blob")?;
|
||||
|
||||
// get the contents
|
||||
let blob_contents = blob.content();
|
||||
@ -1686,7 +1686,7 @@ pub fn commit(
|
||||
) -> Result<()> {
|
||||
// get the files to commit
|
||||
let statuses = get_status_by_branch(gb_repository, project_repository)
|
||||
.expect("failed to get status by branch");
|
||||
.context("failed to get status by branch")?;
|
||||
|
||||
for (mut branch, files) in statuses {
|
||||
if branch.id == branch_id {
|
||||
|
Loading…
Reference in New Issue
Block a user