Skip to content

Commit 9161e60

Browse files
committed
git: Use anyhow errors in write_temporary_ssh_key()
1 parent bdce4f6 commit 9161e60

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/git.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::{anyhow, Context};
12
use std::collections::HashMap;
23
use std::io::Write;
34
use std::path::{Path, PathBuf};
@@ -64,10 +65,10 @@ impl Credentials {
6465
/// - If non-SSH credentials are use, `Err` is returned.
6566
/// - If creation of the temporary file fails, `Err` is returned.
6667
///
67-
pub fn write_temporary_ssh_key(&self) -> Result<tempfile::TempPath, PerformError> {
68+
pub fn write_temporary_ssh_key(&self) -> anyhow::Result<tempfile::TempPath> {
6869
let key = match self {
6970
Credentials::Ssh { key } => key,
70-
_ => return Err("SSH key not available".into()),
71+
_ => return Err(anyhow!("SSH key not available")),
7172
};
7273

7374
let dir = if cfg!(target_os = "linux") {
@@ -78,8 +79,13 @@ impl Credentials {
7879
std::env::temp_dir()
7980
};
8081

81-
let mut temp_key_file = tempfile::Builder::new().tempfile_in(dir)?;
82-
temp_key_file.write_all(key.as_bytes())?;
82+
let mut temp_key_file = tempfile::Builder::new()
83+
.tempfile_in(dir)
84+
.context("Failed to create temporary file")?;
85+
86+
temp_key_file
87+
.write_all(key.as_bytes())
88+
.context("Failed to write SSH key to temporary file")?;
8389

8490
Ok(temp_key_file.into_temp_path())
8591
}

0 commit comments

Comments
 (0)