Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/error.rs @ 46545:d7685105e504
rhg: Parse per-repository configuration
Differential Revision: https://phab.mercurial-scm.org/D9964
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 04 Feb 2021 15:04:53 +0100 |
parents | a6e4e4650bac |
children | eace48b4a786 |
line wrap: on
line diff
--- a/rust/rhg/src/error.rs Thu Feb 04 14:29:47 2021 +0100 +++ b/rust/rhg/src/error.rs Thu Feb 04 15:04:53 2021 +0100 @@ -3,7 +3,7 @@ use format_bytes::format_bytes; use hg::config::{ConfigError, ConfigParseError}; use hg::errors::HgError; -use hg::repo::RepoFindError; +use hg::repo::RepoError; use hg::revlog::revlog::RevlogError; use hg::utils::files::get_bytes_from_path; use std::convert::From; @@ -51,18 +51,17 @@ } } -impl From<RepoFindError> for CommandError { - fn from(error: RepoFindError) -> Self { +impl From<RepoError> for CommandError { + fn from(error: RepoError) -> Self { match error { - RepoFindError::NotFoundInCurrentDirectoryOrAncestors { - current_directory, - } => CommandError::Abort { + RepoError::NotFound { current_directory } => CommandError::Abort { message: format_bytes!( b"no repository found in '{}' (.hg not found)!", get_bytes_from_path(current_directory) ), }, - RepoFindError::Other(error) => error.into(), + RepoError::ConfigParseError(error) => error.into(), + RepoError::Other(error) => error.into(), } } } @@ -70,33 +69,35 @@ impl From<ConfigError> for CommandError { fn from(error: ConfigError) -> Self { match error { - ConfigError::Parse(ConfigParseError { - origin, - line, - bytes, - }) => { - let line_message = if let Some(line_number) = line { - format_bytes!( - b" at line {}", - line_number.to_string().into_bytes() - ) - } else { - Vec::new() - }; - CommandError::Abort { - message: format_bytes!( - b"config parse error in {}{}: '{}'", - origin.to_bytes(), - line_message, - bytes - ), - } - } + ConfigError::Parse(error) => error.into(), ConfigError::Other(error) => error.into(), } } } +impl From<ConfigParseError> for CommandError { + fn from(error: ConfigParseError) -> Self { + let ConfigParseError { + origin, + line, + bytes, + } = error; + let line_message = if let Some(line_number) = line { + format_bytes!(b" at line {}", line_number.to_string().into_bytes()) + } else { + Vec::new() + }; + CommandError::Abort { + message: format_bytes!( + b"config parse error in {}{}: '{}'", + origin.to_bytes(), + line_message, + bytes + ), + } + } +} + impl From<(RevlogError, &str)> for CommandError { fn from((err, rev): (RevlogError, &str)) -> CommandError { match err {