Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/error.rs @ 45984:fada33872b5b
rhg: use `format_bytes!` for error messages
This change also includes a formatting changing with the new `rustfmt` version,
but I'm expecting it to have already been applied in another patch by the time
this lands.
Differential Revision: https://phab.mercurial-scm.org/D9407
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 26 Nov 2020 09:54:16 +0100 |
parents | 2ad2745e0be9 |
children | 3e2d539d0d1a |
line wrap: on
line diff
--- a/rust/rhg/src/error.rs Mon Nov 30 10:18:36 2020 +0100 +++ b/rust/rhg/src/error.rs Thu Nov 26 09:54:16 2020 +0100 @@ -1,5 +1,6 @@ use crate::exitcode; use crate::ui::UiError; +use format_bytes::format_bytes; use hg::operations::{FindRootError, FindRootErrorKind}; use hg::requirements::RequirementsError; use hg::utils::files::get_bytes_from_path; @@ -44,27 +45,17 @@ /// Return the message corresponding to the error kind if any pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> { match self { - // TODO use formating macro CommandErrorKind::RootNotFound(path) => { let bytes = get_bytes_from_path(path); - Some( - [ - b"abort: no repository found in '", - bytes.as_slice(), - b"' (.hg not found)!\n", - ] - .concat(), - ) + Some(format_bytes!( + b"abort: no repository found in '{}' (.hg not found)!\n", + bytes.as_slice() + )) } - // TODO use formating macro - CommandErrorKind::CurrentDirNotFound(e) => Some( - [ - b"abort: error getting current working directory: ", - e.to_string().as_bytes(), - b"\n", - ] - .concat(), - ), + CommandErrorKind::CurrentDirNotFound(e) => Some(format_bytes!( + b"abort: error getting current working directory: {}\n", + e.to_string().as_bytes(), + )), CommandErrorKind::RequirementsError( RequirementsError::Corrupted, ) => Some(