1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27: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:
Sylvestre Ledru 2024-01-06 16:54:29 +01:00 committed by GitHub
parent d158f1a396
commit 247f2e55bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 7 deletions

View file

@ -57,8 +57,8 @@ pub enum FormatError {
IoError(std::io::Error),
NoMoreArguments,
InvalidArgument(FormatArgument),
TooManySpecs,
NeedAtLeastOneSpec,
TooManySpecs(Vec<u8>),
NeedAtLeastOneSpec(Vec<u8>),
WrongSpecType,
}
@ -79,9 +79,16 @@ impl Display for FormatError {
"%{}: invalid conversion specification",
String::from_utf8_lossy(s)
),
// TODO: The next two should print the spec as well
Self::TooManySpecs => write!(f, "format has too many % directives"),
Self::NeedAtLeastOneSpec => write!(f, "format has no % directive"),
Self::TooManySpecs(s) => write!(
f,
"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
Self::WrongSpecType => write!(f, "wrong % directive type was given"),
Self::IoError(_) => write!(f, "io error"),
@ -303,7 +310,9 @@ impl<F: Formatter> Format<F> {
}
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)?;
@ -312,7 +321,7 @@ impl<F: Formatter> Format<F> {
for item in &mut iter {
match item? {
FormatItem::Spec(_) => {
return Err(FormatError::TooManySpecs);
return Err(FormatError::TooManySpecs(format_string.as_ref().to_vec()));
}
FormatItem::Char(c) => suffix.push(c),
}

View file

@ -766,3 +766,17 @@ fn test_invalid_zero_increment_value() {
.no_stdout()
.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");
}