comparison rust/rhg/src/error.rs @ 46797:bcdcb4423ae3

rhg: Add more conversions between error types This allows using the `?` operator in more places, as the next commit does. Differential Revision: https://phab.mercurial-scm.org/D10238
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 19 Mar 2021 13:18:53 +0100
parents b1f2c2b336ec
children 821929d59e01
comparison
equal deleted inserted replaced
46796:38f55ef058fb 46797:bcdcb4423ae3
1 use crate::ui::utf8_to_local; 1 use crate::ui::utf8_to_local;
2 use crate::ui::UiError; 2 use crate::ui::UiError;
3 use crate::NoRepoInCwdError; 3 use crate::NoRepoInCwdError;
4 use format_bytes::format_bytes; 4 use format_bytes::format_bytes;
5 use hg::config::{ConfigError, ConfigParseError}; 5 use hg::config::{ConfigError, ConfigParseError, ConfigValueParseError};
6 use hg::errors::HgError; 6 use hg::errors::HgError;
7 use hg::repo::RepoError; 7 use hg::repo::RepoError;
8 use hg::revlog::revlog::RevlogError; 8 use hg::revlog::revlog::RevlogError;
9 use hg::utils::files::get_bytes_from_path; 9 use hg::utils::files::get_bytes_from_path;
10 use hg::{DirstateError, DirstateMapError, StatusError};
10 use std::convert::From; 11 use std::convert::From;
11 12
12 /// The kind of command error 13 /// The kind of command error
13 #[derive(Debug)] 14 #[derive(Debug)]
14 pub enum CommandError { 15 pub enum CommandError {
56 HgError::UnsupportedFeature(message) => { 57 HgError::UnsupportedFeature(message) => {
57 CommandError::unsupported(message) 58 CommandError::unsupported(message)
58 } 59 }
59 _ => CommandError::abort(error.to_string()), 60 _ => CommandError::abort(error.to_string()),
60 } 61 }
62 }
63 }
64
65 impl From<ConfigValueParseError> for CommandError {
66 fn from(error: ConfigValueParseError) -> Self {
67 CommandError::abort(error.to_string())
61 } 68 }
62 } 69 }
63 70
64 impl From<UiError> for CommandError { 71 impl From<UiError> for CommandError {
65 fn from(_error: UiError) -> Self { 72 fn from(_error: UiError) -> Self {
142 )), 149 )),
143 RevlogError::Other(error) => error.into(), 150 RevlogError::Other(error) => error.into(),
144 } 151 }
145 } 152 }
146 } 153 }
154
155 impl From<StatusError> for CommandError {
156 fn from(error: StatusError) -> Self {
157 CommandError::abort(format!("{}", error))
158 }
159 }
160
161 impl From<DirstateMapError> for CommandError {
162 fn from(error: DirstateMapError) -> Self {
163 CommandError::abort(format!("{}", error))
164 }
165 }
166
167 impl From<DirstateError> for CommandError {
168 fn from(error: DirstateError) -> Self {
169 match error {
170 DirstateError::Common(error) => error.into(),
171 DirstateError::Map(error) => error.into(),
172 }
173 }
174 }