rust/rhg/src/error.rs
changeset 46593 5ce2aa7c2ad5
parent 46591 21d3b40b4c0e
child 46666 33f2d56acc73
equal deleted inserted replaced
46592:80840b651721 46593:5ce2aa7c2ad5
     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 format_bytes::format_bytes;
     4 use format_bytes::format_bytes;
     4 use hg::config::{ConfigError, ConfigParseError};
     5 use hg::config::{ConfigError, ConfigParseError};
     5 use hg::errors::HgError;
     6 use hg::errors::HgError;
     6 use hg::repo::RepoError;
     7 use hg::repo::RepoError;
     7 use hg::revlog::revlog::RevlogError;
     8 use hg::revlog::revlog::RevlogError;
    62 impl From<RepoError> for CommandError {
    63 impl From<RepoError> for CommandError {
    63     fn from(error: RepoError) -> Self {
    64     fn from(error: RepoError) -> Self {
    64         match error {
    65         match error {
    65             RepoError::NotFound { at } => CommandError::Abort {
    66             RepoError::NotFound { at } => CommandError::Abort {
    66                 message: format_bytes!(
    67                 message: format_bytes!(
    67                     b"no repository found in '{}' (.hg not found)!",
    68                     b"repository {} not found",
    68                     get_bytes_from_path(at)
    69                     get_bytes_from_path(at)
    69                 ),
    70                 ),
    70             },
    71             },
    71             RepoError::ConfigParseError(error) => error.into(),
    72             RepoError::ConfigParseError(error) => error.into(),
    72             RepoError::Other(error) => error.into(),
    73             RepoError::Other(error) => error.into(),
       
    74         }
       
    75     }
       
    76 }
       
    77 
       
    78 impl<'a> From<&'a NoRepoInCwdError> for CommandError {
       
    79     fn from(error: &'a NoRepoInCwdError) -> Self {
       
    80         let NoRepoInCwdError { cwd } = error;
       
    81         CommandError::Abort {
       
    82             message: format_bytes!(
       
    83                 b"no repository found in '{}' (.hg not found)!",
       
    84                 get_bytes_from_path(cwd)
       
    85             ),
    73         }
    86         }
    74     }
    87     }
    75 }
    88 }
    76 
    89 
    77 impl From<ConfigError> for CommandError {
    90 impl From<ConfigError> for CommandError {