##// END OF EJS Templates
rhg: Align config file parse error formatting with Python...
Simon Sapin -
r47465:3d692e72 default
parent child Browse files
Show More
@@ -9,7 +9,7 b''
9 9
10 10 use crate::errors::{HgError, IoResultExt};
11 11 use crate::utils::files::{get_bytes_from_path, get_path_from_bytes};
12 use format_bytes::{write_bytes, DisplayBytes};
12 use format_bytes::{format_bytes, write_bytes, DisplayBytes};
13 13 use lazy_static::lazy_static;
14 14 use regex::bytes::Regex;
15 15 use std::collections::HashMap;
@@ -187,10 +187,15 b' impl ConfigLayer {'
187 187 map.remove(&m[1]);
188 188 }
189 189 } else {
190 let message = if bytes.starts_with(b" ") {
191 format_bytes!(b"unexpected leading whitespace: {}", bytes)
192 } else {
193 bytes.to_owned()
194 };
190 195 return Err(ConfigParseError {
191 196 origin: ConfigOrigin::File(src.to_owned()),
192 197 line: Some(index + 1),
193 bytes: bytes.to_owned(),
198 message,
194 199 }
195 200 .into());
196 201 }
@@ -278,7 +283,7 b' impl DisplayBytes for ConfigOrigin {'
278 283 pub struct ConfigParseError {
279 284 pub origin: ConfigOrigin,
280 285 pub line: Option<usize>,
281 pub bytes: Vec<u8>,
286 pub message: Vec<u8>,
282 287 }
283 288
284 289 #[derive(Debug, derive_more::From)]
@@ -78,10 +78,10 b' impl fmt::Display for HgError {'
78 78 match self {
79 79 HgError::Abort(explanation) => write!(f, "{}", explanation),
80 80 HgError::IoError { error, context } => {
81 write!(f, "{}: {}", error, context)
81 write!(f, "abort: {}: {}", context, error)
82 82 }
83 83 HgError::CorruptedRepository(explanation) => {
84 write!(f, "corrupted repository: {}", explanation)
84 write!(f, "abort: corrupted repository: {}", explanation)
85 85 }
86 86 HgError::UnsupportedFeature(explanation) => {
87 87 write!(f, "unsupported feature: {}", explanation)
@@ -128,8 +128,12 b' impl fmt::Display for IoErrorContext {'
128 128 from.display(),
129 129 to.display()
130 130 ),
131 IoErrorContext::CurrentDir => write!(f, "current directory"),
132 IoErrorContext::CurrentExe => write!(f, "current executable"),
131 IoErrorContext::CurrentDir => {
132 write!(f, "error getting current working directory")
133 }
134 IoErrorContext::CurrentExe => {
135 write!(f, "error getting current executable")
136 }
133 137 }
134 138 }
135 139 }
@@ -87,7 +87,7 b" impl<'a> From<&'a NoRepoInCwdError> for "
87 87 let NoRepoInCwdError { cwd } = error;
88 88 CommandError::Abort {
89 89 message: format_bytes!(
90 b"no repository found in '{}' (.hg not found)!",
90 b"abort: no repository found in '{}' (.hg not found)!",
91 91 get_bytes_from_path(cwd)
92 92 ),
93 93 }
@@ -108,19 +108,19 b' impl From<ConfigParseError> for CommandE'
108 108 let ConfigParseError {
109 109 origin,
110 110 line,
111 bytes,
111 message,
112 112 } = error;
113 113 let line_message = if let Some(line_number) = line {
114 format_bytes!(b" at line {}", line_number.to_string().into_bytes())
114 format_bytes!(b":{}", line_number.to_string().into_bytes())
115 115 } else {
116 116 Vec::new()
117 117 };
118 118 CommandError::Abort {
119 119 message: format_bytes!(
120 b"config parse error in {}{}: '{}'",
120 b"config error at {}{}: {}",
121 121 origin,
122 122 line_message,
123 bytes
123 message
124 124 ),
125 125 }
126 126 }
@@ -130,11 +130,11 b' impl From<(RevlogError, &str)> for Comma'
130 130 fn from((err, rev): (RevlogError, &str)) -> CommandError {
131 131 match err {
132 132 RevlogError::InvalidRevision => CommandError::abort(format!(
133 "invalid revision identifier {}",
133 "abort: invalid revision identifier: {}",
134 134 rev
135 135 )),
136 136 RevlogError::AmbiguousPrefix => CommandError::abort(format!(
137 "ambiguous revision identifier {}",
137 "abort: ambiguous revision identifier: {}",
138 138 rev
139 139 )),
140 140 RevlogError::Other(error) => error.into(),
@@ -201,8 +201,7 b' fn exit('
201 201 if !message.is_empty() {
202 202 // Ignore errors when writing to stderr, we’re already exiting
203 203 // with failure code so there’s not much more we can do.
204 let _ =
205 ui.write_stderr(&format_bytes!(b"abort: {}\n", message));
204 let _ = ui.write_stderr(&format_bytes!(b"{}\n", message));
206 205 }
207 206 }
208 207 Err(CommandError::UnsupportedFeature { message }) => {
@@ -45,7 +45,7 b' Unwritable file descriptor'
45 45 Deleted repository
46 46 $ rm -rf `pwd`
47 47 $ $NO_FALLBACK rhg root
48 abort: $ENOENT$: current directory
48 abort: error getting current working directory: $ENOENT$
49 49 [255]
50 50
51 51 Listing tracked files
@@ -122,7 +122,7 b' Specifying revisions by changeset ID'
122 122 $ $NO_FALLBACK rhg cat -r cf8b83 file-2
123 123 2
124 124 $ $NO_FALLBACK rhg cat -r c file-2
125 abort: ambiguous revision identifier c
125 abort: ambiguous revision identifier: c
126 126 [255]
127 127 $ $NO_FALLBACK rhg cat -r d file-2
128 128 2
General Comments 0
You need to be logged in to leave comments. Login now