Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/error.rs @ 46632:5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
? rather than in each sub-command that needs a local repository.
This will allow accessing e.g. `.hg/blackbox.log` before dispatching
to sub-commands.
Differential Revision: https://phab.mercurial-scm.org/D10004
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 15 Feb 2021 20:13:09 +0100 |
parents | 21d3b40b4c0e |
children | 33f2d56acc73 |
line wrap: on
line diff
--- a/rust/rhg/src/error.rs Mon Feb 15 20:05:32 2021 +0100 +++ b/rust/rhg/src/error.rs Mon Feb 15 20:13:09 2021 +0100 @@ -1,5 +1,6 @@ use crate::ui::utf8_to_local; use crate::ui::UiError; +use crate::NoRepoInCwdError; use format_bytes::format_bytes; use hg::config::{ConfigError, ConfigParseError}; use hg::errors::HgError; @@ -64,7 +65,7 @@ match error { RepoError::NotFound { at } => CommandError::Abort { message: format_bytes!( - b"no repository found in '{}' (.hg not found)!", + b"repository {} not found", get_bytes_from_path(at) ), }, @@ -74,6 +75,18 @@ } } +impl<'a> From<&'a NoRepoInCwdError> for CommandError { + fn from(error: &'a NoRepoInCwdError) -> Self { + let NoRepoInCwdError { cwd } = error; + CommandError::Abort { + message: format_bytes!( + b"no repository found in '{}' (.hg not found)!", + get_bytes_from_path(cwd) + ), + } + } +} + impl From<ConfigError> for CommandError { fn from(error: ConfigError) -> Self { match error {