Convert more ShellError variants to named fields (#11222)

# Description

Convert errors to named fields:
* NeedsPositiveValue
* MissingConfigValue
* UnsupportedConfigValue
* DowncastNotPossible
* NonUtf8Custom
* NonUtf8
* DidYouMeanCustom
* DidYouMean
* ReadingFile
* RemoveNotPossible
* ChangedModifiedTimeNotPossible
* ChangedAccessTimeNotPossible

Part of #10700
This commit is contained in:
Eric Hodel
2023-12-04 01:19:32 -08:00
committed by GitHub
parent b227eea668
commit 67eec92e76
26 changed files with 299 additions and 208 deletions

View File

@ -746,14 +746,14 @@ mod windows_helper {
&mut find_data,
) {
Ok(_) => Ok(find_data),
Err(e) => Err(ShellError::ReadingFile(
format!(
Err(e) => Err(ShellError::ReadingFile {
msg: format!(
"Could not read metadata for '{}':\n '{}'",
filename.to_string_lossy(),
e
),
span,
)),
}),
}
}
}

View File

@ -393,7 +393,7 @@ fn rm(
if let Err(e) = result {
let msg = format!("Could not delete {:}: {e:}", f.to_string_lossy());
Value::error(ShellError::RemoveNotPossible(msg, span), span)
Value::error(ShellError::RemoveNotPossible { msg, span }, span)
} else if verbose {
let msg = if interactive && !confirmed {
"not deleted"

View File

@ -151,12 +151,13 @@ impl Command for Touch {
&item,
FileTime::from_system_time(date.expect("should be a valid date").into()),
) {
return Err(ShellError::ChangeModifiedTimeNotPossible(
format!("Failed to change the modified time: {err}"),
call.positional_nth(index)
return Err(ShellError::ChangeModifiedTimeNotPossible {
msg: format!("Failed to change the modified time: {err}"),
span: call
.positional_nth(index)
.expect("already checked positional")
.span,
));
});
};
}
@ -170,12 +171,13 @@ impl Command for Touch {
ref_date_atime.expect("should be a valid date").into(),
),
) {
return Err(ShellError::ChangeAccessTimeNotPossible(
format!("Failed to change the access time: {err}"),
call.positional_nth(index)
return Err(ShellError::ChangeAccessTimeNotPossible {
msg: format!("Failed to change the access time: {err}"),
span: call
.positional_nth(index)
.expect("already checked positional")
.span,
));
});
};
} else {
// Should not panic as we return an error above if we can't parse the date
@ -183,12 +185,13 @@ impl Command for Touch {
&item,
FileTime::from_system_time(date.expect("should be a valid date").into()),
) {
return Err(ShellError::ChangeAccessTimeNotPossible(
format!("Failed to change the access time: {err}"),
call.positional_nth(index)
return Err(ShellError::ChangeAccessTimeNotPossible {
msg: format!("Failed to change the access time: {err}"),
span: call
.positional_nth(index)
.expect("already checked positional")
.span,
));
});
};
}
}