Skip to content

Commit

Permalink
clidispatch: punch "@prog@" variables in abort messages
Browse files Browse the repository at this point in the history
Summary: This way you can use "prog@" more conviently when bailing out with an error that gives advice on what command to run.

Reviewed By: sggutier

Differential Revision: D50570658

fbshipit-source-id: 87b2bfe4e01a0a219df89d8bc29fbc0ddad49af6
  • Loading branch information
muirdm authored and facebook-github-bot committed Oct 23, 2023
1 parent c136fc3 commit 272d970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 9 additions & 2 deletions eden/scm/lib/clidispatch/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ pub struct RepoRequired(pub String);
#[error("malformed --config option: '{0}' (use --config section.name=value)")]
pub struct MalformedConfigOption(pub String);

#[derive(Debug, Error)]
#[error("{0}")]
#[derive(Debug)]
pub struct Abort(pub Cow<'static, str>);

impl std::error::Error for Abort {}

impl std::fmt::Display for Abort {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", identity::default().punch(&self.0))
}
}

/// Print an error suitable for end-user consumption.
///
/// This function adds `hg:` or `abort:` to error messages.
Expand Down
5 changes: 2 additions & 3 deletions eden/scm/lib/hgcommands/src/commands/goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use anyhow::bail;
use anyhow::Result;
use clidispatch::abort;
use clidispatch::fallback;
use clidispatch::ReqCtx;
use cliparser::define_flags;
Expand Down Expand Up @@ -85,9 +86,7 @@ pub fn run(ctx: ReqCtx<GotoOpts>, repo: &mut Repo, wc: &mut WorkingCopy) -> Resu
}

if dest.is_empty() {
bail!(identity::default().punch(
r#"You must specify a destination to update to, for example "@prog@ goto main"."#,
));
abort!(r#"You must specify a destination to update to, for example "@prog@ goto main"."#);
}
if dest.len() > 1 {
bail!(
Expand Down

0 comments on commit 272d970

Please sign in to comment.