mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
repo_path: don't panic on invalid UTF-8 path component
Although watchman client appears to fail at decoding non-UTF-8 path (somewhere in serde), jj shouldn't panic if watchman could deal with that. The outer error message "path not in the repo" would sounds odd, but I think that's okay because 1. it's unlikely that a user input is not UTF-8, and 2. it's technically correct that a non-UTF-8 path is not contained in the repo.
This commit is contained in:
parent
a224d0f172
commit
fa60026f25
1 changed files with 8 additions and 1 deletions
|
@ -211,7 +211,12 @@ impl RepoPathBuf {
|
||||||
let mut components = relative_path
|
let mut components = relative_path
|
||||||
.components()
|
.components()
|
||||||
.map(|c| match c {
|
.map(|c| match c {
|
||||||
Component::Normal(name) => Ok(name.to_str().unwrap()),
|
Component::Normal(name) => {
|
||||||
|
name.to_str()
|
||||||
|
.ok_or_else(|| RelativePathParseError::InvalidUtf8 {
|
||||||
|
path: relative_path.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
_ => Err(RelativePathParseError::InvalidComponent {
|
_ => Err(RelativePathParseError::InvalidComponent {
|
||||||
component: c.as_os_str().to_string_lossy().into(),
|
component: c.as_os_str().to_string_lossy().into(),
|
||||||
path: relative_path.into(),
|
path: relative_path.into(),
|
||||||
|
@ -424,6 +429,8 @@ pub enum RelativePathParseError {
|
||||||
component: Box<str>,
|
component: Box<str>,
|
||||||
path: Box<Path>,
|
path: Box<Path>,
|
||||||
},
|
},
|
||||||
|
#[error(r#"Not valid UTF-8 path "{path}""#)]
|
||||||
|
InvalidUtf8 { path: Box<Path> },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Error, PartialEq)]
|
#[derive(Clone, Debug, Eq, Error, PartialEq)]
|
||||||
|
|
Loading…
Reference in a new issue