avoid directly indexing when possible

This commit is contained in:
figsoda 2023-01-05 14:33:37 -05:00
parent e06b2c8635
commit c7165fb52c

View File

@ -149,11 +149,10 @@ pub fn run(
let error = FinalError::with_title(format!("Cannot compress to '{output_path}'.")) let error = FinalError::with_title(format!("Cannot compress to '{output_path}'."))
.detail(first_detail_message) .detail(first_detail_message)
.detail(format!( .detail(format!(
"The compression format '{}' does not accept multiple files.", "The compression format '{first_format}' does not accept multiple files.",
&formats[0]
)) ))
.detail("Formats that bundle files into an archive are .tar and .zip.") .detail("Formats that bundle files into an archive are .tar and .zip.")
.hint(format!("Try inserting '.tar' or '.zip' before '{}'.", &formats[0])) .hint(format!("Try inserting '.tar' or '.zip' before '{first_format}'."))
.hint(format!("From: {output_path}")) .hint(format!("From: {output_path}"))
.hint(format!("To: {suggested_output_path}")); .hint(format!("To: {suggested_output_path}"));
@ -245,7 +244,7 @@ pub fn run(
.map(|(input_path, _)| PathBuf::from(input_path)) .map(|(input_path, _)| PathBuf::from(input_path))
.collect(); .collect();
if !files_missing_format.is_empty() { if let Some(path) = files_missing_format.first() {
let error = FinalError::with_title("Cannot decompress files without extensions") let error = FinalError::with_title("Cannot decompress files without extensions")
.detail(format!( .detail(format!(
"Files without supported extensions: {}", "Files without supported extensions: {}",
@ -258,7 +257,7 @@ pub fn run(
.hint("Or overwrite this option with the '--format' flag:") .hint("Or overwrite this option with the '--format' flag:")
.hint(format!( .hint(format!(
" ouch decompress {} --format tar.gz", " ouch decompress {} --format tar.gz",
to_utf(&files_missing_format[0]) EscapedPathDisplay::new(path),
)); ));
return Err(error.into()); return Err(error.into());