[Request] [+- ] D10838: rhg: add exit code to HgError::Abort()
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Mon Jun 7 12:01:12 UTC 2021
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
My previous attempts to have rhg end with correct exit code was more of bug
hunting. I found cases which were failing and fixed them. But as one might
expect, more tests started failing.
Let's add exit code `HgError::Abort()` and make it users explicitly tell what
exit code they want.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10838
AFFECTED FILES
rust/hg-core/src/config/layer.rs
rust/hg-core/src/errors.rs
rust/hg-core/src/repo.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -152,6 +152,7 @@
Some(b"abort") | None => HgError::abort(
"abort: share source does not support share-safe requirement\n\
(see `hg help config.format.use-share-safe` for more information)",
+ 30,
),
_ => HgError::unsupported("share-safe downgrade"),
}
@@ -163,6 +164,7 @@
"abort: version mismatch: source uses share-safe \
functionality while the current share does not\n\
(see `hg help config.format.use-share-safe` for more information)",
+ 30,
),
_ => HgError::unsupported("share-safe upgrade"),
}
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
@@ -29,7 +29,7 @@
///
/// The given string is a short explanation for users, not intended to be
/// machine-readable.
- Abort(String),
+ Abort(String, i32),
/// A configuration value is not in the expected syntax.
///
@@ -69,8 +69,9 @@
pub fn unsupported(explanation: impl Into<String>) -> Self {
HgError::UnsupportedFeature(explanation.into())
}
- pub fn abort(explanation: impl Into<String>) -> Self {
- HgError::Abort(explanation.into())
+
+ pub fn abort(explanation: impl Into<String>, exit_code: i32) -> Self {
+ HgError::Abort(explanation.into(), exit_code)
}
}
@@ -78,7 +79,7 @@
impl fmt::Display for HgError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- HgError::Abort(explanation) => write!(f, "{}", explanation),
+ HgError::Abort(explanation, _) => write!(f, "{}", explanation),
HgError::IoError { error, context } => {
write!(f, "abort: {}: {}", context, error)
}
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
@@ -73,11 +73,14 @@
if let Some((section, item, value)) = parse_one(arg) {
layer.add(section, item, value, None);
} else {
- Err(HgError::abort(format!(
- "abort: malformed --config option: '{}' \
+ Err(HgError::abort(
+ format!(
+ "abort: malformed --config option: '{}' \
(use --config section.name=value)",
- String::from_utf8_lossy(arg),
- )))?
+ String::from_utf8_lossy(arg),
+ ),
+ 10,
+ ))?
}
}
if layer.sections.is_empty() {
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210607/cecc26b3/attachment-0001.html>
More information about the Mercurial-patches
mailing list