Patchwork D10145: rhg: Return an error code for `rhg config Section.idontexist`

login
register
mail settings
Submitter phabricator
Date March 9, 2021, 9:42 a.m.
Message ID <differential-rev-PHID-DREV-yfbguwpb3v5lljpvvjp5-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48459/
State Superseded
Headers show

Comments

phabricator - March 9, 2021, 9:42 a.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10145

AFFECTED FILES
  rust/rhg/src/commands/config.rs

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/rhg/src/commands/config.rs b/rust/rhg/src/commands/config.rs
--- a/rust/rhg/src/commands/config.rs
+++ b/rust/rhg/src/commands/config.rs
@@ -29,8 +29,10 @@ 
         .split_2(b'.')
         .ok_or_else(|| HgError::unsupported("hg config <section>"))?;
 
-    let value = invocation.config.get(section, name).unwrap_or(b"");
-
-    invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?;
-    Ok(())
+    if let Some(value) = invocation.config.get(section, name) {
+        invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?;
+        Ok(())
+    } else {
+        Err(CommandError::Unsuccessful)
+    }
 }