From fa60026f25d938a52beb9c7d8852d2c65c6ad838 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 20 Nov 2023 17:28:21 +0900 Subject: [PATCH] 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. --- lib/src/repo_path.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/repo_path.rs b/lib/src/repo_path.rs index 122f99204..086a7d199 100644 --- a/lib/src/repo_path.rs +++ b/lib/src/repo_path.rs @@ -211,7 +211,12 @@ impl RepoPathBuf { let mut components = relative_path .components() .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 { component: c.as_os_str().to_string_lossy().into(), path: relative_path.into(), @@ -424,6 +429,8 @@ pub enum RelativePathParseError { component: Box, path: Box, }, + #[error(r#"Not valid UTF-8 path "{path}""#)] + InvalidUtf8 { path: Box }, } #[derive(Clone, Debug, Eq, Error, PartialEq)]