Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/error.rs @ 46543:a6e4e4650bac
rhg: Parse system and user configuration at program start
? and pass it around up to `Repo::find`
Differential Revision: https://phab.mercurial-scm.org/D9962
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 04 Feb 2021 13:17:55 +0100 |
parents | 1dcd9c9975ed |
children | d7685105e504 |
line wrap: on
line diff
--- a/rust/rhg/src/error.rs Thu Feb 04 13:16:21 2021 +0100 +++ b/rust/rhg/src/error.rs Thu Feb 04 13:17:55 2021 +0100 @@ -1,6 +1,7 @@ use crate::ui::utf8_to_local; use crate::ui::UiError; use format_bytes::format_bytes; +use hg::config::{ConfigError, ConfigParseError}; use hg::errors::HgError; use hg::repo::RepoFindError; use hg::revlog::revlog::RevlogError; @@ -66,6 +67,36 @@ } } +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::Other(error) => error.into(), + } + } +} + impl From<(RevlogError, &str)> for CommandError { fn from((err, rev): (RevlogError, &str)) -> CommandError { match err {