rust/rhg/src/error.rs
changeset 45999 fada33872b5b
parent 45952 2ad2745e0be9
child 46502 3e2d539d0d1a
equal deleted inserted replaced
45998:97205cf0ee4d 45999:fada33872b5b
     1 use crate::exitcode;
     1 use crate::exitcode;
     2 use crate::ui::UiError;
     2 use crate::ui::UiError;
       
     3 use format_bytes::format_bytes;
     3 use hg::operations::{FindRootError, FindRootErrorKind};
     4 use hg::operations::{FindRootError, FindRootErrorKind};
     4 use hg::requirements::RequirementsError;
     5 use hg::requirements::RequirementsError;
     5 use hg::utils::files::get_bytes_from_path;
     6 use hg::utils::files::get_bytes_from_path;
     6 use std::convert::From;
     7 use std::convert::From;
     7 use std::path::PathBuf;
     8 use std::path::PathBuf;
    42     }
    43     }
    43 
    44 
    44     /// Return the message corresponding to the error kind if any
    45     /// Return the message corresponding to the error kind if any
    45     pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
    46     pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
    46         match self {
    47         match self {
    47             // TODO use formating macro
       
    48             CommandErrorKind::RootNotFound(path) => {
    48             CommandErrorKind::RootNotFound(path) => {
    49                 let bytes = get_bytes_from_path(path);
    49                 let bytes = get_bytes_from_path(path);
    50                 Some(
    50                 Some(format_bytes!(
    51                     [
    51                     b"abort: no repository found in '{}' (.hg not found)!\n",
    52                         b"abort: no repository found in '",
    52                     bytes.as_slice()
    53                         bytes.as_slice(),
    53                 ))
    54                         b"' (.hg not found)!\n",
       
    55                     ]
       
    56                     .concat(),
       
    57                 )
       
    58             }
    54             }
    59             // TODO use formating macro
    55             CommandErrorKind::CurrentDirNotFound(e) => Some(format_bytes!(
    60             CommandErrorKind::CurrentDirNotFound(e) => Some(
    56                 b"abort: error getting current working directory: {}\n",
    61                 [
    57                 e.to_string().as_bytes(),
    62                     b"abort: error getting current working directory: ",
    58             )),
    63                     e.to_string().as_bytes(),
       
    64                     b"\n",
       
    65                 ]
       
    66                 .concat(),
       
    67             ),
       
    68             CommandErrorKind::RequirementsError(
    59             CommandErrorKind::RequirementsError(
    69                 RequirementsError::Corrupted,
    60                 RequirementsError::Corrupted,
    70             ) => Some(
    61             ) => Some(
    71                 "abort: .hg/requires is corrupted\n".as_bytes().to_owned(),
    62                 "abort: .hg/requires is corrupted\n".as_bytes().to_owned(),
    72             ),
    63             ),