Skip to content

Commit 4d913fa

Browse files
authored
Merge pull request #4639 from epage/error
fix(error): Try to soften unexpected argument/value errors
2 parents 34d856b + 162a556 commit 4d913fa

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

examples/derive_ref/interop_tests.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Value of derived: DerivedArgs {
3535
```console
3636
$ interop_augment_args --unknown
3737
? failed
38-
error: unexpected argument '--unknown'
38+
error: unexpected argument '--unknown' found
3939

4040
Usage: interop_augment_args[EXE] [OPTIONS]
4141

@@ -70,7 +70,7 @@ Derived subcommands: Derived {
7070
```console
7171
$ interop_augment_subcommands derived --unknown
7272
? failed
73-
error: unexpected argument '--unknown'
73+
error: unexpected argument '--unknown' found
7474

7575
Usage: interop_augment_subcommands[EXE] derived [OPTIONS]
7676

@@ -140,7 +140,7 @@ Cli {
140140
```console
141141
$ interop_hand_subcommand add --unknown
142142
? failed
143-
error: unexpected argument '--unknown'
143+
error: unexpected argument '--unknown' found
144144

145145
note: to pass '--unknown' as a value, use '-- --unknown'
146146

@@ -239,7 +239,7 @@ Cli {
239239
```console
240240
$ interop_flatten_hand_args --unknown
241241
? failed
242-
error: unexpected argument '--unknown'
242+
error: unexpected argument '--unknown' found
243243

244244
Usage: interop_flatten_hand_args[EXE] [OPTIONS]
245245

examples/escaped-positional-derive.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Notice that we can't pass positional arguments before `--`:
3333
```console
3434
$ escaped-positional-derive foo bar
3535
? failed
36-
error: unexpected argument 'foo'
36+
error: unexpected argument 'foo' found
3737

3838
Usage: escaped-positional-derive[EXE] [OPTIONS] [-- <SLOP>...]
3939

examples/escaped-positional.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Notice that we can't pass positional arguments before `--`:
3333
```console
3434
$ escaped-positional foo bar
3535
? failed
36-
error: unexpected argument 'foo'
36+
error: unexpected argument 'foo' found
3737

3838
Usage: escaped-positional[EXE] [OPTIONS] [-- <SLOP>...]
3939

src/error/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) ->
282282
styled.warning(invalid_value);
283283
styled.none("' for '");
284284
styled.warning(invalid_arg);
285-
styled.none("'; no more were expected");
285+
styled.none("' found; no more were expected");
286286
true
287287
} else {
288288
false
@@ -360,7 +360,7 @@ fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) ->
360360
if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
361361
styled.none("unexpected argument '");
362362
styled.warning(invalid_arg.to_string());
363-
styled.none("'");
363+
styled.none("' found");
364364
true
365365
} else {
366366
false

src/error/kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ impl ErrorKind {
317317
pub fn as_str(self) -> Option<&'static str> {
318318
match self {
319319
Self::InvalidValue => Some("one of the values isn't valid for an argument"),
320-
Self::UnknownArgument => Some("unexpected argument"),
320+
Self::UnknownArgument => Some("unexpected argument found"),
321321
Self::InvalidSubcommand => Some("unrecognized subcommand"),
322322
Self::NoEquals => Some("equal is needed when assigning values to one of the arguments"),
323323
Self::ValueValidation => Some("invalid value for one of the arguments"),
324-
Self::TooManyValues => Some("unexpected value for an argument"),
324+
Self::TooManyValues => Some("unexpected value for an argument found"),
325325
Self::TooFewValues => Some("more values required for an argument"),
326326
Self::WrongNumberOfValues => Some("too many or too few values for an argument"),
327327
Self::ArgumentConflict => {

tests/builder/conflicts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn args_negate_subcommands_two_levels() {
734734
#[cfg(feature = "error-context")]
735735
fn subcommand_conflict_error_message() {
736736
static CONFLICT_ERR: &str = "\
737-
error: unexpected argument 'sub1'
737+
error: unexpected argument 'sub1' found
738738
739739
Usage: test [OPTIONS]
740740
test <COMMAND>

tests/builder/error.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn kind_formats_validation_error() {
106106
let err = res.unwrap_err();
107107
let expected_kind = ErrorKind::UnknownArgument;
108108
static MESSAGE: &str = "\
109-
error: unexpected argument
109+
error: unexpected argument found
110110
";
111111
assert_error(err, expected_kind, MESSAGE, true);
112112
}
@@ -120,7 +120,7 @@ fn rich_formats_validation_error() {
120120
let err = res.unwrap_err();
121121
let expected_kind = ErrorKind::UnknownArgument;
122122
static MESSAGE: &str = "\
123-
error: unexpected argument 'unused'
123+
error: unexpected argument 'unused' found
124124
125125
Usage: test
126126
@@ -139,7 +139,7 @@ fn suggest_trailing() {
139139
let err = res.unwrap_err();
140140
let expected_kind = ErrorKind::UnknownArgument;
141141
static MESSAGE: &str = "\
142-
error: unexpected argument '--foo'
142+
error: unexpected argument '--foo' found
143143
144144
note: to pass '--foo' as a value, use '-- --foo'
145145
@@ -160,7 +160,7 @@ fn trailing_already_in_use() {
160160
let err = res.unwrap_err();
161161
let expected_kind = ErrorKind::UnknownArgument;
162162
static MESSAGE: &str = "\
163-
error: unexpected argument '--foo'
163+
error: unexpected argument '--foo' found
164164
165165
Usage: rg [PATTERN]
166166
@@ -179,7 +179,7 @@ fn cant_use_trailing() {
179179
let err = res.unwrap_err();
180180
let expected_kind = ErrorKind::UnknownArgument;
181181
static MESSAGE: &str = "\
182-
error: unexpected argument '--foo'
182+
error: unexpected argument '--foo' found
183183
184184
Usage: test
185185

tests/builder/flags.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn multiple_flags_in_single() {
140140
#[cfg(feature = "error-context")]
141141
fn unexpected_value_error() {
142142
const USE_FLAG_AS_ARGUMENT: &str = "\
143-
error: unexpected value 'foo' for '--a-flag'; no more were expected
143+
error: unexpected value 'foo' for '--a-flag' found; no more were expected
144144
145145
Usage: mycat --a-flag [filename]
146146
@@ -158,7 +158,7 @@ For more information, try '--help'.
158158
#[cfg(feature = "error-context")]
159159
fn issue_1284_argument_in_flag_style() {
160160
const USE_FLAG_AS_ARGUMENT: &str = "\
161-
error: unexpected argument '--another-flag'
161+
error: unexpected argument '--another-flag' found
162162
163163
note: to pass '--another-flag' as a value, use '-- --another-flag'
164164
@@ -202,7 +202,7 @@ For more information, try '--help'.
202202
#[cfg(feature = "error-context")]
203203
fn issue_2308_multiple_dashes() {
204204
static MULTIPLE_DASHES: &str = "\
205-
error: unexpected argument '-----'
205+
error: unexpected argument '-----' found
206206
207207
note: to pass '-----' as a value, use '-- -----'
208208

tests/builder/opts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ fn leading_hyphen_with_only_pos_follows() {
446446
#[cfg(feature = "error-context")]
447447
fn did_you_mean() {
448448
static DYM: &str = "\
449-
error: unexpected argument '--optio'
449+
error: unexpected argument '--optio' found
450450
451451
note: argument '--option' exists
452452
@@ -544,7 +544,7 @@ fn issue_1105_empty_value_short_explicit_no_space() {
544544
#[cfg(feature = "error-context")]
545545
fn issue_1073_suboptimal_flag_suggestion() {
546546
static DYM_ISSUE_1073: &str = "\
547-
error: unexpected argument '--files-without-matches'
547+
error: unexpected argument '--files-without-matches' found
548548
549549
note: argument '--files-without-match' exists
550550

tests/builder/subcommands.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ For more information, try '--help'.
139139
#[cfg(feature = "error-context")]
140140
fn subcmd_did_you_mean_output_arg() {
141141
static EXPECTED: &str = "\
142-
error: unexpected argument '--subcmarg'
142+
error: unexpected argument '--subcmarg' found
143143
144144
note: 'subcmd --subcmdarg' exists
145145
@@ -159,7 +159,7 @@ For more information, try '--help'.
159159
#[cfg(feature = "error-context")]
160160
fn subcmd_did_you_mean_output_arg_false_positives() {
161161
static EXPECTED: &str = "\
162-
error: unexpected argument '--subcmarg'
162+
error: unexpected argument '--subcmarg' found
163163
164164
Usage: dym [COMMAND]
165165
@@ -351,7 +351,7 @@ fn subcommand_placeholder_test() {
351351
#[cfg(feature = "error-context")]
352352
fn subcommand_used_after_double_dash() {
353353
static SUBCMD_AFTER_DOUBLE_DASH: &str = "\
354-
error: unexpected argument 'subcmd'
354+
error: unexpected argument 'subcmd' found
355355
356356
note: subcommand 'subcmd' exists; to use it, remove the '--' before it
357357

tests/ui/error_stderr.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ args = ["--unknown-argument"]
33
status.code = 2
44
stdout = ""
55
stderr = """
6-
error: unexpected argument '--unknown-argument'
6+
error: unexpected argument '--unknown-argument' found
77
88
Usage: stdio-fixture[EXE] [OPTIONS] [COMMAND]
99

0 commit comments

Comments
 (0)