Mercurial > hg
changeset 46731:3d692e724d06
rhg: Align config file parse error formatting with Python
Differences can cause tests to fail
Differential Revision: https://phab.mercurial-scm.org/D10110
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 03 Mar 2021 19:47:48 +0100 |
parents | dfd35823635b |
children | 60fe9ebae29b |
files | rust/hg-core/src/config/layer.rs rust/hg-core/src/errors.rs rust/rhg/src/error.rs rust/rhg/src/main.rs tests/test-rhg.t |
diffstat | 5 files changed, 26 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/config/layer.rs Wed Mar 03 19:08:27 2021 +0100 +++ b/rust/hg-core/src/config/layer.rs Wed Mar 03 19:47:48 2021 +0100 @@ -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<usize>, - pub bytes: Vec<u8>, + pub message: Vec<u8>, } #[derive(Debug, derive_more::From)]
--- a/rust/hg-core/src/errors.rs Wed Mar 03 19:08:27 2021 +0100 +++ b/rust/hg-core/src/errors.rs Wed Mar 03 19:47:48 2021 +0100 @@ -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") + } } } }
--- a/rust/rhg/src/error.rs Wed Mar 03 19:08:27 2021 +0100 +++ b/rust/rhg/src/error.rs Wed Mar 03 19:47:48 2021 +0100 @@ -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(),
--- a/rust/rhg/src/main.rs Wed Mar 03 19:08:27 2021 +0100 +++ b/rust/rhg/src/main.rs Wed Mar 03 19:47:48 2021 +0100 @@ -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 }) => {
--- a/tests/test-rhg.t Wed Mar 03 19:08:27 2021 +0100 +++ b/tests/test-rhg.t Wed Mar 03 19:47:48 2021 +0100 @@ -45,7 +45,7 @@ Deleted repository $ rm -rf `pwd` $ $NO_FALLBACK rhg root - abort: $ENOENT$: current directory + abort: error getting current working directory: $ENOENT$ [255] Listing tracked files @@ -122,7 +122,7 @@ $ $NO_FALLBACK rhg cat -r cf8b83 file-2 2 $ $NO_FALLBACK rhg cat -r c file-2 - abort: ambiguous revision identifier c + abort: ambiguous revision identifier: c [255] $ $NO_FALLBACK rhg cat -r d file-2 2