Standardized error messages: constant names

Part of #12556
This commit is contained in:
Nahor
2026-03-20 09:19:45 -07:00
committed by Johannes Altmanninger
parent 434610494f
commit f3f675b4cc
8 changed files with 28 additions and 26 deletions

View File

@@ -22,8 +22,8 @@
builtins::{
fish_indent, fish_key_reader,
shared::{
BUILTIN_ERR_MISSING, BUILTIN_ERR_UNEXP_ARG, BUILTIN_ERR_UNKNOWN, STATUS_CMD_ERROR,
STATUS_CMD_OK, STATUS_CMD_UNKNOWN, VERSION_STRING_TEMPLATE,
BUILTIN_ERR_MISSING_OPT_ARG, BUILTIN_ERR_UNEXP_OPT_ARG, BUILTIN_ERR_UNKNOWN_OPT,
STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_CMD_UNKNOWN, VERSION_STRING_TEMPLATE,
},
},
common::{
@@ -320,21 +320,21 @@ fn fish_parse_opt(args: &mut [WString], opts: &mut FishCmdOpts) -> ControlFlow<i
'?' => {
eprintf!(
"%s\n\n",
wgettext_fmt!(BUILTIN_ERR_UNKNOWN, "fish", args[w.wopt_index - 1])
wgettext_fmt!(BUILTIN_ERR_UNKNOWN_OPT, "fish", args[w.wopt_index - 1])
);
return ControlFlow::Break(1);
}
':' => {
eprintf!(
"%s\n\n",
wgettext_fmt!(BUILTIN_ERR_MISSING, "fish", args[w.wopt_index - 1])
wgettext_fmt!(BUILTIN_ERR_MISSING_OPT_ARG, "fish", args[w.wopt_index - 1])
);
return ControlFlow::Break(1);
}
';' => {
eprintf!(
"%s\n\n",
wgettext_fmt!(BUILTIN_ERR_UNEXP_ARG, "fish", args[w.wopt_index - 1])
wgettext_fmt!(BUILTIN_ERR_UNEXP_OPT_ARG, "fish", args[w.wopt_index - 1])
);
return ControlFlow::Break(1);
}

View File

@@ -962,7 +962,7 @@ fn argparse_parse_flags<'args>(
)?;
} else if opts.unknown_handling == UnknownHandling::Error {
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNKNOWN,
BUILTIN_ERR_UNKNOWN_OPT,
opts.name,
args_read[w.wopt_index - 1]
));
@@ -1017,7 +1017,7 @@ fn argparse_parse_flags<'args>(
} else {
// the option is at the end of argv, so it has no argument
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_MISSING,
BUILTIN_ERR_MISSING_OPT_ARG,
opts.name,
args_read[w.wopt_index - 1]
));
@@ -1033,7 +1033,7 @@ fn argparse_parse_flags<'args>(
&& arg_contents.contains('=')
{
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNEXP_ARG,
BUILTIN_ERR_UNEXP_OPT_ARG,
opts.name,
args_read[w.wopt_index - 1]
));

View File

@@ -1027,7 +1027,7 @@ enum OutputType {
'c' => output_type = OutputType::Check,
';' => {
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNEXP_ARG,
BUILTIN_ERR_UNEXP_OPT_ARG,
"fish_indent",
w.argv[w.wopt_index - 1]
));
@@ -1035,7 +1035,7 @@ enum OutputType {
}
'?' => {
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNKNOWN,
BUILTIN_ERR_UNKNOWN_OPT,
"fish_indent",
w.argv[w.wopt_index - 1]
));

View File

@@ -12,7 +12,7 @@
use libc::{STDIN_FILENO, VEOF, VINTR};
use crate::{
builtins::shared::BUILTIN_ERR_UNKNOWN,
builtins::shared::BUILTIN_ERR_UNKNOWN_OPT,
common::{PROGRAM_NAME, get_program_name, osstr2wcstring, shell_modes},
env::{EnvStack, Environment as _, env_init},
future_feature_flags,
@@ -213,7 +213,7 @@ fn parse_flags(
}
';' => {
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNEXP_ARG,
BUILTIN_ERR_UNEXP_OPT_ARG,
"fish_key_reader",
w.argv[w.wopt_index - 1]
));
@@ -221,7 +221,7 @@ fn parse_flags(
}
'?' => {
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_UNKNOWN,
BUILTIN_ERR_UNKNOWN_OPT,
"fish_key_reader",
w.argv[w.wopt_index - 1]
));

View File

@@ -28,7 +28,7 @@ macro_rules! path_error {
}
fn path_unknown_option(parser: &Parser, streams: &mut IoStreams, subcmd: &wstr, opt: &wstr) {
path_error!(streams, BUILTIN_ERR_UNKNOWN, subcmd, opt);
path_error!(streams, BUILTIN_ERR_UNKNOWN_OPT, subcmd, opt);
builtin_print_error_trailer(parser, streams.err, L!("path"));
}

View File

@@ -294,9 +294,11 @@ fn validate(
}
if args.len() == optind && opts.erase {
streams
.err
.appendln(&wgettext_fmt!(BUILTIN_ERR_MISSING, cmd, L!("--erase")));
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_MISSING_OPT_ARG,
cmd,
L!("--erase")
));
builtin_print_error_trailer(parser, streams.err, cmd);
return Err(STATUS_INVALID_ARGS);
}

View File

@@ -20,11 +20,11 @@
localizable_consts!(
/// Error message on missing argument.
pub BUILTIN_ERR_MISSING
pub BUILTIN_ERR_MISSING_OPT_ARG
"%s: %s: option requires an argument"
/// Error message on unexpected argument.
pub BUILTIN_ERR_UNEXP_ARG
pub BUILTIN_ERR_UNEXP_OPT_ARG
"%s: %s: option does not take an argument"
/// Error message on missing man page.
@@ -44,7 +44,7 @@
"%s: cannot both path and unpath"
/// Error message for unknown switch.
pub BUILTIN_ERR_UNKNOWN
pub BUILTIN_ERR_UNKNOWN_OPT
"%s: %s: unknown option"
/// Error message for invalid bind mode name.
@@ -667,7 +667,7 @@ pub fn builtin_unknown_option(
) {
streams
.err
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNKNOWN, cmd, opt));
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNKNOWN_OPT, cmd, opt));
if print_hints {
builtin_print_error_trailer(parser, streams.err, cmd);
}
@@ -685,14 +685,14 @@ pub fn builtin_missing_argument(
// if c in -qc '-qc' is missing the argument, now opt is just 'c'
opt = &opt[opt.len() - 1..];
streams.err.appendln(&wgettext_fmt!(
BUILTIN_ERR_MISSING,
BUILTIN_ERR_MISSING_OPT_ARG,
cmd,
L!("-").to_owned() + opt
));
} else {
streams
.err
.appendln(&wgettext_fmt!(BUILTIN_ERR_MISSING, cmd, opt));
.appendln(&wgettext_fmt!(BUILTIN_ERR_MISSING_OPT_ARG, cmd, opt));
}
if print_hints {
builtin_print_error_trailer(parser, streams.err, cmd);
@@ -709,7 +709,7 @@ pub fn builtin_unexpected_argument(
) {
streams
.err
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNEXP_ARG, cmd, opt));
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNEXP_OPT_ARG, cmd, opt));
if print_hints {
builtin_print_error_trailer(parser, streams.err, cmd);
}
@@ -1042,7 +1042,7 @@ pub fn builtin_break_continue(
if argc != 1 {
streams
.err
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNKNOWN, argv[0], argv[1]));
.appendln(&wgettext_fmt!(BUILTIN_ERR_UNKNOWN_OPT, argv[0], argv[1]));
return Err(STATUS_INVALID_ARGS);
}

View File

@@ -84,7 +84,7 @@ fn parse_opts(
'?' => {
string_error!(
streams,
BUILTIN_ERR_UNKNOWN,
BUILTIN_ERR_UNKNOWN_OPT,
cmd,
args_read[w.wopt_index - 1]
);