Improved labeled error from plugins (#437)

* improved labeled error from plugins

* corrected span
This commit is contained in:
Fernando Herrera
2021-12-05 03:11:19 +00:00
committed by GitHub
parent 03e22b071a
commit 22469a9cb1
24 changed files with 611 additions and 208 deletions

View File

@ -83,32 +83,32 @@ impl Command for Cp {
let prompt = format!(
"Are you shure that you want to copy {} to {}?",
file.as_ref()
.map_err(|err| ShellError::LabeledError(
.map_err(|err| ShellError::SpannedLabeledError(
"Reference error".into(),
err.to_string(),
call.head
))?
.file_name()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"File name error".into(),
"Unable to get file name".into(),
call.head
))?
.to_str()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"Unable to get str error".into(),
"Unable to convert to str file name".into(),
call.head
))?,
destination
.file_name()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"File name error".into(),
"Unable to get file name".into(),
call.head
))?
.to_str()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"Unable to get str error".into(),
"Unable to convert to str file name".into(),
call.head

View File

@ -56,7 +56,7 @@ impl Command for Ls {
let call_span = call.head;
let glob = glob::glob(&pattern).map_err(|err| {
nu_protocol::ShellError::LabeledError(
nu_protocol::ShellError::SpannedLabeledError(
"Error extracting glob pattern".into(),
err.to_string(),
call.head,

View File

@ -67,32 +67,32 @@ impl Command for Mv {
let prompt = format!(
"Are you shure that you want to move {} to {}?",
file.as_ref()
.map_err(|err| ShellError::LabeledError(
.map_err(|err| ShellError::SpannedLabeledError(
"Reference error".into(),
err.to_string(),
call.head
))?
.file_name()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"File name error".into(),
"Unable to get file name".into(),
call.head
))?
.to_str()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"Unable to get str error".into(),
"Unable to convert to str file name".into(),
call.head
))?,
destination
.file_name()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"File name error".into(),
"Unable to get file name".into(),
call.head
))?
.to_str()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"Unable to get str error".into(),
"Unable to convert to str file name".into(),
call.head

View File

@ -126,13 +126,13 @@ fn rm(
"Are you sure that you what to delete {}?",
file.1
.file_name()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"File name error".into(),
"Unable to get file name".into(),
call.head
))?
.to_str()
.ok_or_else(|| ShellError::LabeledError(
.ok_or_else(|| ShellError::SpannedLabeledError(
"Unable to get str error".into(),
"Unable to convert to str file name".into(),
call.head
@ -188,7 +188,7 @@ fn rm_helper(call: &Call, args: RmArgs) -> Vec<Value> {
{
if trash {
let error = match call.get_flag_expr("trash").ok_or_else(|| {
ShellError::LabeledError(
ShellError::SpannedLabeledError(
"Flag not found".into(),
"trash flag not found".into(),
call.head,