mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 20:37:14 +02:00
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:
@ -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,
|
||||
)),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
));
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user