Skip to content

Commit 8cab772

Browse files
committed
git: Use anyhow errors in write_temporary_ssh_key()
1 parent de0eb0a commit 8cab772

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};
@@ -61,10 +62,10 @@ impl Credentials {
6162
/// - If non-SSH credentials are use, `Err` is returned.
6263
/// - If creation of the temporary file fails, `Err` is returned.
6364
///
64-
pub fn write_temporary_ssh_key(&self) -> Result<tempfile::TempPath, PerformError> {
65+
pub fn write_temporary_ssh_key(&self) -> anyhow::Result<tempfile::TempPath> {
6566
let key = match self {
6667
Credentials::Ssh { key } => key,
67-
_ => return Err("SSH key not available".into()),
68+
_ => return Err(anyhow!("SSH key not available")),
6869
};
6970

7071
let dir = if cfg!(target_os = "linux") {
@@ -75,8 +76,13 @@ impl Credentials {
7576
std::env::temp_dir()
7677
};
7778

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

8187
Ok(temp_key_file.into_temp_path())
8288
}

0 commit comments

Comments
 (0)