improve misleading error message (#818)

Follow up to #817
This commit is contained in:
João Marcos 2025-05-06 00:27:43 -03:00 committed by GitHub
parent c8f97197c3
commit c3b89b038d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 16 deletions

View File

@ -64,7 +64,7 @@ Categories Used:
### Improvements
- Fix logging IO bottleneck [\#642](https://github.com/ouch-org/ouch/pull/642) ([AntoniosBarotsis](https://github.com/AntoniosBarotsis))
- Support decompression over stdin [\#692](https://github.com/ouch-org/ouch/pull/692) ([rcorre](https://github.com/rcorre))
- Support decompression over stdin [\#692](https://github.com/ouch-org/ouch/pull/692) ([rcorre](https://github.com/rcorre))
- Make `--format` more forgiving with the formatting of the provided format [\#519](https://github.com/ouch-org/ouch/pull/519) ([marcospb19](https://github.com/marcospb19))
- Use buffered writer for list output [\#764](https://github.com/ouch-org/ouch/pull/764) ([killercup](https://github.com/killercup))
- Disable smart unpack when `--dir` flag is provided in decompress command [\#782](https://github.com/ouch-org/ouch/pull/782) ([talis-fb](https://github.com/talis-fb))

View File

@ -203,24 +203,23 @@ pub fn separate_known_extensions_from_name(path: &Path) -> Result<(&Path, Vec<Ex
extensions.insert(0, extension);
if extensions[0].is_archive() {
if let Some((_, misplaced_extension)) = split_extension_at_end(name) {
return Err(FinalError::with_title("File extensions are invalid for operation")
.detail(format!(
"The archive extension '.{}' must come before any non-archive extensions, like '.{}'",
extensions[0].display_text, misplaced_extension.display_text
))
.detail(format!(
let mut error = FinalError::with_title("File extensions are invalid for operation").detail(format!(
"The archive extension '.{}' can only be placed at the start of the extension list",
extensions[0].display_text,
));
if misplaced_extension.compression_formats == extensions[0].compression_formats {
error = error.detail(format!(
"File: '{path:?}' contains '.{}' and '.{}'",
misplaced_extension.display_text, extensions[0].display_text,
))
.detail(format!("'.{}' is an archive format", extensions[0].display_text))
.detail(format!(
"'.{}' isn't an archive format",
misplaced_extension.display_text
))
));
}
return Err(error
.hint("You can use `--format` to specify what format to use, examples:")
.hint(" ouch compress 1 2 file --format zip")
.hint(" ouch decompress file --format gz")
.hint(" ouch list archive --format zip")
.hint(" ouch compress file.zip.zip file --format zip")
.hint(" ouch decompress file --format zst")
.hint(" ouch list archive --format tar.gz")
.into());
}
break;