Skip to content

Commit

Permalink
parser: use backtick to quote name or expression in error message
Browse files Browse the repository at this point in the history
I don't have any preference about quoting styles, but it looks weird if an
escaped symbol is surrounded by double quotes.
  • Loading branch information
yuja committed Feb 3, 2025
1 parent f31abfd commit ce123a6
Show file tree
Hide file tree
Showing 28 changed files with 447 additions and 472 deletions.
6 changes: 3 additions & 3 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl AdvanceBookmarksSettings {
.into_iter()
.map(|s| {
StringPattern::parse(&s).map_err(|e| {
config_error_with_message(format!("Error parsing '{s}' for {name}"), e)
config_error_with_message(format!("Error parsing `{s}` for {name}"), e)
})
})
.collect(),
Expand Down Expand Up @@ -2875,7 +2875,7 @@ pub fn load_template_aliases(
if let Err(s) = r {
writeln!(
ui.warning_default(),
r#"Failed to load "{table_name}.{decl}": {s}"#
"Failed to load `{table_name}.{decl}`: {s}"
)?;
}
}
Expand Down Expand Up @@ -3330,7 +3330,7 @@ fn resolve_aliases(
.collect_vec();
if resolved_aliases.contains(&*alias_name) {
return Err(user_error(format!(
r#"Recursive alias definition involving "{alias_name}""#
"Recursive alias definition involving `{alias_name}`"
)));
}
if let Some(&alias_name) = defined_aliases.get(&*alias_name) {
Expand Down
7 changes: 2 additions & 5 deletions cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ fn format_similarity_hint<S: AsRef<str>>(candidates: &[S]) -> Option<String> {
match candidates {
[] => None,
names => {
let quoted_names = names
.iter()
.map(|s| format!(r#""{}""#, s.as_ref()))
.join(", ");
let quoted_names = names.iter().map(|s| format!("`{}`", s.as_ref())).join(", ");
Some(format!("Did you mean {quoted_names}?"))
}
}
Expand Down Expand Up @@ -820,7 +817,7 @@ fn revset_parse_error_hint(err: &RevsetParseError) -> Option<String> {
op: _,
similar_op,
description,
} => Some(format!("Did you mean '{similar_op}' for {description}?")),
} => Some(format!("Did you mean `{similar_op}` for {description}?")),
RevsetParseErrorKind::NoSuchFunction {
name: _,
candidates,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn write_repository_level_trunk_alias(
file.save()?;
writeln!(
ui.status(),
r#"Setting the revset alias "trunk()" to "{branch}@{remote}""#,
"Setting the revset alias `trunk()` to `{branch}@{remote}`",
)?;
Ok(())
}
14 changes: 7 additions & 7 deletions cli/src/revset_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn load_revset_aliases(
if let Err(s) = r {
writeln!(
ui.warning_default(),
r#"Failed to load "{table_name}.{decl}": {s}"#
"Failed to load `{table_name}.{decl}`: {s}"
)?;
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ pub(super) fn evaluate_revset_to_single_commit<'a>(
match (iter.next(), iter.next()) {
(Some(commit), None) => Ok(commit?),
(None, _) => Err(user_error(format!(
r#"Revset "{revision_str}" didn't resolve to any revisions"#
"Revset `{revision_str}` didn't resolve to any revisions"
))),
(Some(commit0), Some(commit1)) => {
let mut iter = [commit0, commit1].into_iter().chain(iter);
Expand Down Expand Up @@ -295,7 +295,7 @@ fn format_multiple_revisions_error(
) -> CommandError {
assert!(commits.len() >= 2);
let mut cmd_err = user_error(format!(
r#"Revset "{revision_str}" resolved to more than one revision"#
"Revset `{revision_str}` resolved to more than one revision"
));
let write_commits_summary = |formatter: &mut dyn Formatter| {
for commit in commits {
Expand All @@ -313,7 +313,7 @@ fn format_multiple_revisions_error(
cmd_err.add_formatted_hint_with(|formatter| {
writeln!(
formatter,
r#"The revset "{revision_str}" resolved to these revisions:"#
"The revset `{revision_str}` resolved to these revisions:"
)?;
write_commits_summary(formatter)
});
Expand All @@ -339,14 +339,14 @@ fn format_multiple_revisions_error(
cmd_err.add_formatted_hint_with(|formatter| {
writeln!(
formatter,
r#"The revset "{revision_str}" resolved to these revisions:"#
"The revset `{revision_str}` resolved to these revisions:"
)?;
write_commits_summary(formatter)
});
if should_hint_about_all_prefix {
cmd_err.add_hint(format!(
"Prefix the expression with 'all:' to allow any number of revisions (i.e. \
'all:{revision_str}')."
"Prefix the expression with `all:` to allow any number of revisions (i.e. \
`all:{revision_str}`)."
));
}
};
Expand Down
Loading

0 comments on commit ce123a6

Please sign in to comment.