From 977cfd3d4a5224d94e252cad367071bdf81ef431 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 23 Oct 2022 13:39:38 +0900 Subject: [PATCH] repo_path: make FsPathParseError displayable by itself So it can be easily embedded in other error types such as RevsetError. --- lib/src/repo_path.rs | 4 +++- src/cli_util.rs | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/src/repo_path.rs b/lib/src/repo_path.rs index 243cffdfd..f192239f9 100644 --- a/lib/src/repo_path.rs +++ b/lib/src/repo_path.rs @@ -16,6 +16,7 @@ use std::fmt::{Debug, Error, Formatter}; use std::path::{Component, Path, PathBuf}; use itertools::Itertools; +use thiserror::Error; use crate::file_util; @@ -178,8 +179,9 @@ impl RepoPathJoin for RepoPath { } } -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, Error, PartialEq)] pub enum FsPathParseError { + #[error(r#"Path "{0}" is not in the repo"#)] InputNotInRepo(String), } diff --git a/src/cli_util.rs b/src/cli_util.rs index 85c482e75..10adbf30a 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -168,11 +168,7 @@ impl From for CommandError { impl From for CommandError { fn from(err: FsPathParseError) -> Self { - match err { - FsPathParseError::InputNotInRepo(input) => { - CommandError::UserError(format!("Path \"{input}\" is not in the repo")) - } - } + CommandError::UserError(format!("{err}")) } }