mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
seq: adjust some error messages. GNU's are better (#5798)
* seq: adjust some error messages. GNU's are better tested by tests/seq/seq.pl * uucore: remove todo --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
d158f1a396
commit
247f2e55bd
2 changed files with 30 additions and 7 deletions
|
@ -57,8 +57,8 @@ pub enum FormatError {
|
||||||
IoError(std::io::Error),
|
IoError(std::io::Error),
|
||||||
NoMoreArguments,
|
NoMoreArguments,
|
||||||
InvalidArgument(FormatArgument),
|
InvalidArgument(FormatArgument),
|
||||||
TooManySpecs,
|
TooManySpecs(Vec<u8>),
|
||||||
NeedAtLeastOneSpec,
|
NeedAtLeastOneSpec(Vec<u8>),
|
||||||
WrongSpecType,
|
WrongSpecType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +79,16 @@ impl Display for FormatError {
|
||||||
"%{}: invalid conversion specification",
|
"%{}: invalid conversion specification",
|
||||||
String::from_utf8_lossy(s)
|
String::from_utf8_lossy(s)
|
||||||
),
|
),
|
||||||
// TODO: The next two should print the spec as well
|
Self::TooManySpecs(s) => write!(
|
||||||
Self::TooManySpecs => write!(f, "format has too many % directives"),
|
f,
|
||||||
Self::NeedAtLeastOneSpec => write!(f, "format has no % directive"),
|
"format '{}' has too many % directives",
|
||||||
|
String::from_utf8_lossy(s)
|
||||||
|
),
|
||||||
|
Self::NeedAtLeastOneSpec(s) => write!(
|
||||||
|
f,
|
||||||
|
"format '{}' has no % directive",
|
||||||
|
String::from_utf8_lossy(s)
|
||||||
|
),
|
||||||
// TODO: Error message below needs some work
|
// TODO: Error message below needs some work
|
||||||
Self::WrongSpecType => write!(f, "wrong % directive type was given"),
|
Self::WrongSpecType => write!(f, "wrong % directive type was given"),
|
||||||
Self::IoError(_) => write!(f, "io error"),
|
Self::IoError(_) => write!(f, "io error"),
|
||||||
|
@ -303,7 +310,9 @@ impl<F: Formatter> Format<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(spec) = spec else {
|
let Some(spec) = spec else {
|
||||||
return Err(FormatError::NeedAtLeastOneSpec);
|
return Err(FormatError::NeedAtLeastOneSpec(
|
||||||
|
format_string.as_ref().to_vec(),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let formatter = F::try_from_spec(spec)?;
|
let formatter = F::try_from_spec(spec)?;
|
||||||
|
@ -312,7 +321,7 @@ impl<F: Formatter> Format<F> {
|
||||||
for item in &mut iter {
|
for item in &mut iter {
|
||||||
match item? {
|
match item? {
|
||||||
FormatItem::Spec(_) => {
|
FormatItem::Spec(_) => {
|
||||||
return Err(FormatError::TooManySpecs);
|
return Err(FormatError::TooManySpecs(format_string.as_ref().to_vec()));
|
||||||
}
|
}
|
||||||
FormatItem::Char(c) => suffix.push(c),
|
FormatItem::Char(c) => suffix.push(c),
|
||||||
}
|
}
|
||||||
|
|
|
@ -766,3 +766,17 @@ fn test_invalid_zero_increment_value() {
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.usage_error("invalid Zero increment value: '0'");
|
.usage_error("invalid Zero increment value: '0'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_format() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-f", "%%g", "1"])
|
||||||
|
.fails()
|
||||||
|
.no_stdout()
|
||||||
|
.stderr_contains("format '%%g' has no % directive");
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-f", "%g%g", "1"])
|
||||||
|
.fails()
|
||||||
|
.no_stdout()
|
||||||
|
.stderr_contains("format '%g%g' has too many % directives");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue