diff --git a/rust/hg-core/src/config/layer.rs b/rust/hg-core/src/config/layer.rs --- a/rust/hg-core/src/config/layer.rs +++ b/rust/hg-core/src/config/layer.rs @@ -9,7 +9,7 @@ use crate::errors::{HgError, IoResultExt}; use crate::utils::files::{get_bytes_from_path, get_path_from_bytes}; -use format_bytes::{write_bytes, DisplayBytes}; +use format_bytes::{format_bytes, write_bytes, DisplayBytes}; use lazy_static::lazy_static; use regex::bytes::Regex; use std::collections::HashMap; @@ -187,10 +187,15 @@ map.remove(&m[1]); } } else { + let message = if bytes.starts_with(b" ") { + format_bytes!(b"unexpected leading whitespace: {}", bytes) + } else { + bytes.to_owned() + }; return Err(ConfigParseError { origin: ConfigOrigin::File(src.to_owned()), line: Some(index + 1), - bytes: bytes.to_owned(), + message, } .into()); } @@ -278,7 +283,7 @@ pub struct ConfigParseError { pub origin: ConfigOrigin, pub line: Option, - pub bytes: Vec, + pub message: Vec, } #[derive(Debug, derive_more::From)] diff --git a/rust/hg-core/src/errors.rs b/rust/hg-core/src/errors.rs --- a/rust/hg-core/src/errors.rs +++ b/rust/hg-core/src/errors.rs @@ -78,10 +78,10 @@ match self { HgError::Abort(explanation) => write!(f, "{}", explanation), HgError::IoError { error, context } => { - write!(f, "{}: {}", error, context) + write!(f, "abort: {}: {}", context, error) } HgError::CorruptedRepository(explanation) => { - write!(f, "corrupted repository: {}", explanation) + write!(f, "abort: corrupted repository: {}", explanation) } HgError::UnsupportedFeature(explanation) => { write!(f, "unsupported feature: {}", explanation) @@ -128,8 +128,12 @@ from.display(), to.display() ), - IoErrorContext::CurrentDir => write!(f, "current directory"), - IoErrorContext::CurrentExe => write!(f, "current executable"), + IoErrorContext::CurrentDir => { + write!(f, "error getting current working directory") + } + IoErrorContext::CurrentExe => { + write!(f, "error getting current executable") + } } } } diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs --- a/rust/rhg/src/error.rs +++ b/rust/rhg/src/error.rs @@ -87,7 +87,7 @@ let NoRepoInCwdError { cwd } = error; CommandError::Abort { message: format_bytes!( - b"no repository found in '{}' (.hg not found)!", + b"abort: no repository found in '{}' (.hg not found)!", get_bytes_from_path(cwd) ), } @@ -108,19 +108,19 @@ let ConfigParseError { origin, line, - bytes, + message, } = error; let line_message = if let Some(line_number) = line { - format_bytes!(b" at line {}", line_number.to_string().into_bytes()) + format_bytes!(b":{}", line_number.to_string().into_bytes()) } else { Vec::new() }; CommandError::Abort { message: format_bytes!( - b"config parse error in {}{}: '{}'", + b"config error at {}{}: {}", origin, line_message, - bytes + message ), } } @@ -130,11 +130,11 @@ fn from((err, rev): (RevlogError, &str)) -> CommandError { match err { RevlogError::InvalidRevision => CommandError::abort(format!( - "invalid revision identifier {}", + "abort: invalid revision identifier: {}", rev )), RevlogError::AmbiguousPrefix => CommandError::abort(format!( - "ambiguous revision identifier {}", + "abort: ambiguous revision identifier: {}", rev )), RevlogError::Other(error) => error.into(), diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs +++ b/rust/rhg/src/main.rs @@ -201,8 +201,7 @@ if !message.is_empty() { // Ignore errors when writing to stderr, we’re already exiting // with failure code so there’s not much more we can do. - let _ = - ui.write_stderr(&format_bytes!(b"abort: {}\n", message)); + let _ = ui.write_stderr(&format_bytes!(b"{}\n", message)); } } Err(CommandError::UnsupportedFeature { message }) => { diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -45,7 +45,7 @@ Deleted repository $ rm -rf `pwd` $ rhg $NO_FALLBACK root - abort: $ENOENT$: current directory + abort: error getting current working directory: $ENOENT$ [255] Listing tracked files @@ -122,7 +122,7 @@ $ rhg $NO_FALLBACK cat -r cf8b83 file-2 2 $ rhg $NO_FALLBACK cat -r c file-2 - abort: ambiguous revision identifier c + abort: ambiguous revision identifier: c [255] $ rhg $NO_FALLBACK cat -r d file-2 2