Skip to content

Commit 3b55f25

Browse files
svetli-nByron
authored andcommitted
Use context in PathError.
1 parent fefb01b commit 3b55f25

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: git-config/src/values.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{borrow::Cow, convert::TryFrom, fmt::Display, str::FromStr};
55
use nom::AsChar;
66
#[cfg(not(target_os = "windows"))]
77
use pwd::Passwd;
8-
use quick_error::quick_error;
8+
use quick_error::{quick_error, ResultExt};
99
#[cfg(feature = "serde")]
1010
use serde::{Serialize, Serializer};
1111

@@ -286,9 +286,9 @@ quick_error! {
286286
Missing { what: &'static str } {
287287
display("{} is missing", what)
288288
}
289-
Utf8Conversion(err: git_features::path::Utf8Error) {
290-
display("Ill-formed UTF-8 in git install dir or home dir")
291-
from()
289+
Utf8Conversion(what: &'static str, err: git_features::path::Utf8Error) {
290+
display("Ill-formed UTF-8 in {}", what)
291+
context(what: &'static str, err: git_features::path::Utf8Error) -> (what, err)
292292
}
293293
UsernameConversion(err: std::str::Utf8Error) {
294294
display("Ill-formed UTF-8 in username")
@@ -323,7 +323,6 @@ impl<'a> TryFrom<Cow<'a, [u8]>> for Path<'a> {
323323
}
324324

325325
impl Path<'_> {
326-
327326
/// Interpolates path value
328327
///
329328
/// Path value can be given a string that begins with `~/` or `~user/` or `%(prefix)/`
@@ -348,7 +347,8 @@ impl Path<'_> {
348347
if path.starts_with(PREFIX) {
349348
let mut expanded = git_features::path::into_bytes(git_install_dir.ok_or(PathError::Missing {
350349
what: "git install dir",
351-
})?)?
350+
})?)
351+
.context("git install dir")?
352352
.into_owned();
353353
let (_prefix, val) = path.split_at(PREFIX.len() - 1);
354354
expanded.extend(val);
@@ -357,7 +357,9 @@ impl Path<'_> {
357357
})
358358
} else if path.starts_with(b"~/") {
359359
let home_path = dirs::home_dir().ok_or(PathError::Missing { what: "home dir" })?;
360-
let mut expanded = git_features::path::into_bytes(home_path)?.into_owned();
360+
let mut expanded = git_features::path::into_bytes(home_path)
361+
.context("home dir")?
362+
.into_owned();
361363
let (_prefix, val) = path.split_at(SLASH.len());
362364
expanded.extend(val);
363365
let expanded = git_features::path::convert::to_unix_separators(expanded);

0 commit comments

Comments
 (0)