update miette and switch to GenericErrors (#5222)

This commit is contained in:
Kat Marchán 2022-04-18 05:34:10 -07:00 committed by GitHub
parent cf65f77b02
commit 1314a87cb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
141 changed files with 1569 additions and 689 deletions

18
Cargo.lock generated
View File

@ -2026,13 +2026,13 @@ dependencies = [
[[package]] [[package]]
name = "miette" name = "miette"
version = "4.4.0" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a097de91d72c13382f60213ed9f7f7a26afd8bee0ea320b47f886a9a67ca5a1" checksum = "01ff8e2f24552a78cbf93f2b197f6a788192200c7200648514647cce438714bf"
dependencies = [ dependencies = [
"atty", "atty",
"backtrace", "backtrace",
"miette-derive 4.4.0", "miette-derive 4.5.0",
"once_cell", "once_cell",
"owo-colors", "owo-colors",
"supports-color", "supports-color",
@ -2057,9 +2057,9 @@ dependencies = [
[[package]] [[package]]
name = "miette-derive" name = "miette-derive"
version = "4.4.0" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45a95a48d0bc28f9af628286e8a4da09f96f34a97744a2e9a5a4db9814ad527d" checksum = "7119608a3ee194199d537849bb7b600f9e04bb1c91b98fb2620b9a867f17ef20"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2244,7 +2244,7 @@ dependencies = [
"is_executable", "is_executable",
"itertools", "itertools",
"log", "log",
"miette 4.4.0", "miette 4.5.0",
"nu-ansi-term", "nu-ansi-term",
"nu-cli", "nu-cli",
"nu-color-config", "nu-color-config",
@ -2286,7 +2286,7 @@ dependencies = [
"crossterm", "crossterm",
"is_executable", "is_executable",
"log", "log",
"miette 4.4.0", "miette 4.5.0",
"nu-ansi-term", "nu-ansi-term",
"nu-color-config", "nu-color-config",
"nu-engine", "nu-engine",
@ -2431,7 +2431,7 @@ version = "0.61.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"log", "log",
"miette 4.4.0", "miette 4.5.0",
"nu-path", "nu-path",
"nu-plugin", "nu-plugin",
"nu-protocol", "nu-protocol",
@ -2475,7 +2475,7 @@ dependencies = [
"chrono", "chrono",
"chrono-humanize", "chrono-humanize",
"indexmap", "indexmap",
"miette 4.4.0", "miette 4.5.0",
"nu-json", "nu-json",
"num-format", "num-format",
"regex", "regex",

View File

@ -36,7 +36,7 @@ chrono = "0.4.19"
crossterm = "0.23.0" crossterm = "0.23.0"
ctrlc = "3.2.1" ctrlc = "3.2.1"
log = "0.4" log = "0.4"
miette = "4.1.0" miette = "4.5.0"
nu-ansi-term = "0.45.1" nu-ansi-term = "0.45.1"
nu-cli = { path="./crates/nu-cli", version = "0.61.1" } nu-cli = { path="./crates/nu-cli", version = "0.61.1" }
nu-color-config = { path = "./crates/nu-color-config", version = "0.61.1" } nu-color-config = { path = "./crates/nu-color-config", version = "0.61.1" }

View File

@ -16,7 +16,7 @@ nu-ansi-term = "0.45.1"
nu-color-config = { path = "../nu-color-config", version = "0.61.1" } nu-color-config = { path = "../nu-color-config", version = "0.61.1" }
crossterm = "0.23.0" crossterm = "0.23.0"
miette = { version = "4.4.0", features = ["fancy"] } miette = { version = "4.5.0", features = ["fancy"] }
thiserror = "1.0.29" thiserror = "1.0.29"
reedline = { version = "0.4.0", features = ["bashisms"]} reedline = { version = "0.4.0", features = ["bashisms"]}

View File

@ -262,7 +262,7 @@ pub fn evaluate_repl(
report_error( report_error(
&working_set, &working_set,
&ShellError::DirectoryNotFound(tokens.0[0].span), &ShellError::DirectoryNotFound(tokens.0[0].span, None),
); );
} }

View File

@ -106,9 +106,12 @@ fn gather_env_vars(vars: impl Iterator<Item = (String, String)>, engine_state: &
let working_set = StateWorkingSet::new(engine_state); let working_set = StateWorkingSet::new(engine_state);
report_error( report_error(
&working_set, &working_set,
&ShellError::LabeledError( &ShellError::GenericError(
format!("Environment variable was not captured: {}", env_str), format!("Environment variable was not captured: {}", env_str),
msg.into(), "".to_string(),
None,
Some(msg.into()),
Vec::new(),
), ),
); );
} }
@ -152,9 +155,12 @@ fn gather_env_vars(vars: impl Iterator<Item = (String, String)>, engine_state: &
let working_set = StateWorkingSet::new(engine_state); let working_set = StateWorkingSet::new(engine_state);
report_error( report_error(
&working_set, &working_set,
&ShellError::LabeledError( &ShellError::GenericError(
"Current directory not found".to_string(), "Current directory not found".to_string(),
format!("Retrieving current directory failed: {:?}", e), "".to_string(),
None,
Some(format!("Retrieving current directory failed: {:?}", e)),
Vec::new(),
), ),
); );
} }

View File

@ -136,11 +136,14 @@ fn string_to_boolean(s: &str, span: Span) -> Result<bool, ShellError> {
let val = o.parse::<f64>(); let val = o.parse::<f64>();
match val { match val {
Ok(f) => Ok(f.abs() >= f64::EPSILON), Ok(f) => Ok(f.abs() >= f64::EPSILON),
Err(_) => Err(ShellError::CantConvertWithHelp( Err(_) => Err(ShellError::CantConvert(
"boolean".to_string(), "boolean".to_string(),
"string".to_string(), "string".to_string(),
span, span,
r#"the strings "true" and "false" can be converted into a bool"#.to_string(), Some(
r#"the strings "true" and "false" can be converted into a bool"#
.to_string(),
),
)), )),
} }
} }

View File

@ -260,11 +260,11 @@ fn action(
Ok(d) => Value::Date { val: d, span: head }, Ok(d) => Value::Date { val: d, span: head },
Err(reason) => { Err(reason) => {
return Value::Error { return Value::Error {
error: ShellError::CantConvertWithHelp( error: ShellError::CantConvert(
format!("could not parse as datetime using format '{}'", dt.0), format!("could not parse as datetime using format '{}'", dt.0),
reason.to_string(), reason.to_string(),
head, head,
"you can use `into datetime` without a format string to enable flexible parsing".to_string() Some("you can use `into datetime` without a format string to enable flexible parsing".to_string())
), ),
} }
} }

View File

@ -101,7 +101,12 @@ fn action(input: &Value, head: Span) -> Value {
match other.parse::<f64>() { match other.parse::<f64>() {
Ok(x) => Value::Float { val: x, span: head }, Ok(x) => Value::Float { val: x, span: head },
Err(reason) => Value::Error { Err(reason) => Value::Error {
error: ShellError::CantConvert("float".to_string(), reason.to_string(), *span), error: ShellError::CantConvert(
"float".to_string(),
reason.to_string(),
*span,
None,
),
}, },
} }
} }

View File

@ -151,11 +151,11 @@ fn string_to_duration(s: &str, span: Span) -> Result<i64, ShellError> {
} }
} }
Err(ShellError::CantConvertWithHelp( Err(ShellError::CantConvert(
"duration".to_string(), "duration".to_string(),
"string".to_string(), "string".to_string(),
span, span,
"supported units are ns, us, ms, sec, min, hr, day, and wk".to_string(), Some("supported units are ns, us, ms, sec, min, hr, day, and wk".to_string()),
)) ))
} }

View File

@ -148,7 +148,12 @@ pub fn action(input: &Value, span: Span) -> Value {
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> { fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
match a_string.trim().parse::<bytesize::ByteSize>() { match a_string.trim().parse::<bytesize::ByteSize>() {
Ok(n) => Ok(n.0 as i64), Ok(n) => Ok(n.0 as i64),
Err(_) => Err(ShellError::CantConvert("int".into(), "string".into(), span)), Err(_) => Err(ShellError::CantConvert(
"int".into(),
"string".into(),
span,
None,
)),
} }
} }

View File

@ -207,7 +207,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
match i64::from_str_radix(&i, radix) { match i64::from_str_radix(&i, radix) {
Ok(n) => Value::Int { val: n, span: head }, Ok(n) => Value::Int { val: n, span: head },
Err(_reason) => Value::Error { Err(_reason) => Value::Error {
error: ShellError::CantConvert("int".to_string(), "string".to_string(), head), error: ShellError::CantConvert("int".to_string(), "string".to_string(), head, None),
}, },
} }
} }
@ -219,29 +219,30 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
let num = match i64::from_str_radix(b.trim_start_matches("0b"), 2) { let num = match i64::from_str_radix(b.trim_start_matches("0b"), 2) {
Ok(n) => n, Ok(n) => n,
Err(_reason) => { Err(_reason) => {
return Err(ShellError::CantConvertWithHelp( return Err(ShellError::CantConvert(
"int".to_string(), "int".to_string(),
"string".to_string(), "string".to_string(),
span, span,
r#"digits following "0b" can only be 0 or 1"#.to_string(), Some(r#"digits following "0b" can only be 0 or 1"#.to_string()),
)) ))
} }
}; };
Ok(num) Ok(num)
} }
h if h.starts_with("0x") => { h if h.starts_with("0x") => {
let num = match i64::from_str_radix(h.trim_start_matches("0x"), 16) { let num =
Ok(n) => n, match i64::from_str_radix(h.trim_start_matches("0x"), 16) {
Err(_reason) => { Ok(n) => n,
return Err(ShellError::CantConvertWithHelp( Err(_reason) => return Err(ShellError::CantConvert(
"int".to_string(), "int".to_string(),
"string".to_string(), "string".to_string(),
span, span,
r#"hexadecimal digits following "0x" should be in 0-9, a-f, or A-F"# Some(
.to_string(), r#"hexadecimal digits following "0x" should be in 0-9, a-f, or A-F"#
)) .to_string(),
} ),
}; )),
};
Ok(num) Ok(num)
} }
_ => match a_string.parse::<i64>() { _ => match a_string.parse::<i64>() {
@ -252,6 +253,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
"int".to_string(), "int".to_string(),
"string".to_string(), "string".to_string(),
span, span,
None,
)), )),
}, },
}, },

View File

@ -258,15 +258,20 @@ pub fn action(
), ),
}, },
Value::Binary { .. } => Value::Error { Value::Binary { .. } => Value::Error {
error: ShellError::CantConvertWithHelp( error: ShellError::CantConvert(
"string".into(), "string".into(),
"binary".into(), "binary".into(),
span, span,
"try using the `decode` command".into(), Some("try using the `decode` command".into()),
), ),
}, },
x => Value::Error { x => Value::Error {
error: ShellError::CantConvert(String::from("string"), x.get_type().to_string(), span), error: ShellError::CantConvert(
String::from("string"),
x.get_type().to_string(),
span,
None,
),
}, },
} }
} }

View File

@ -39,10 +39,12 @@ impl Command for ErrorMake {
Ok(make_error(&arg) Ok(make_error(&arg)
.map(|err| Value::Error { error: err }) .map(|err| Value::Error { error: err })
.unwrap_or_else(|| Value::Error { .unwrap_or_else(|| Value::Error {
error: ShellError::SpannedLabeledError( error: ShellError::GenericError(
"Creating error value not supported.".into(), "Creating error value not supported.".into(),
"unsupported error format".into(), "unsupported error format".into(),
span, Some(span),
None,
Vec::new(),
), ),
}) })
.into_pipeline_data()) .into_pipeline_data())
@ -52,10 +54,12 @@ impl Command for ErrorMake {
make_error(&value) make_error(&value)
.map(|err| Value::Error { error: err }) .map(|err| Value::Error { error: err })
.unwrap_or_else(|| Value::Error { .unwrap_or_else(|| Value::Error {
error: ShellError::SpannedLabeledError( error: ShellError::GenericError(
"Creating error value not supported.".into(), "Creating error value not supported.".into(),
"unsupported error format".into(), "unsupported error format".into(),
span, Some(span),
None,
Vec::new(),
), ),
}) })
}, },
@ -103,20 +107,26 @@ fn make_error(value: &Value) -> Option<ShellError> {
Some(Value::String { Some(Value::String {
val: label_text, .. val: label_text, ..
}), }),
) => Some(ShellError::SpannedLabeledError( ) => Some(ShellError::GenericError(
message, message,
label_text, label_text,
Span { Some(Span {
start: start as usize, start: start as usize,
end: end as usize, end: end as usize,
}, }),
None,
Vec::new(),
)), )),
_ => None, _ => None,
} }
} }
(Some(Value::String { val: message, .. }), None) => { (Some(Value::String { val: message, .. }), None) => Some(ShellError::GenericError(
Some(ShellError::UnlabeledError(message)) message,
} "".to_string(),
None,
None,
Vec::new(),
)),
_ => None, _ => None,
} }
} else { } else {

View File

@ -48,10 +48,12 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
{ {
pat pat
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Unexpected import".into(), "Unexpected import".into(),
"import pattern not supported".into(), "import pattern not supported".into(),
call.head, Some(call.head),
None,
Vec::new(),
)); ));
}; };

View File

@ -100,6 +100,7 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
"bool".into(), "bool".into(),
x.get_type().to_string(), x.get_type().to_string(),
result.span()?, result.span()?,
None,
)), )),
} }
} }

View File

@ -46,10 +46,12 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
{ {
pat pat
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Unexpected import".into(), "Unexpected import".into(),
"import pattern not supported".into(), "import pattern not supported".into(),
call.head, Some(call.head),
None,
Vec::new(),
)); ));
}; };
@ -120,13 +122,15 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
} else { } else {
// TODO: This is a workaround since call.positional[0].span points at 0 for some reason // TODO: This is a workaround since call.positional[0].span points at 0 for some reason
// when this error is triggered // when this error is triggered
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
format!( format!(
"Could not import from '{}'", "Could not import from '{}'",
String::from_utf8_lossy(&import_pattern.head.name) String::from_utf8_lossy(&import_pattern.head.name)
), ),
"module does not exist".to_string(), "module does not exist".to_string(),
import_pattern.head.span, Some(import_pattern.head.span),
None,
Vec::new(),
)); ));
} }

View File

@ -43,17 +43,21 @@ impl Operation {
"last" => Ok(Operation::Last), "last" => Ok(Operation::Last),
"nunique" => Ok(Operation::Nunique), "nunique" => Ok(Operation::Nunique),
"quantile" => match quantile { "quantile" => match quantile {
None => Err(ShellError::SpannedLabeledError( None => Err(ShellError::GenericError(
"Quantile value not fount".into(), "Quantile value not fount".into(),
"Quantile operation requires quantile value".into(), "Quantile operation requires quantile value".into(),
name.span, Some(name.span),
None,
Vec::new(),
)), )),
Some(value) => { Some(value) => {
if (value.item < 0.0) | (value.item > 1.0) { if (value.item < 0.0) | (value.item > 1.0) {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Inappropriate quantile".into(), "Inappropriate quantile".into(),
"Quantile value should be between 0.0 and 1.0".into(), "Quantile value should be between 0.0 and 1.0".into(),
value.span, Some(value.span),
None,
Vec::new(),
)) ))
} else { } else {
Ok(Operation::Quantile(value.item)) Ok(Operation::Quantile(value.item))
@ -82,11 +86,12 @@ impl Operation {
match did_you_mean(&possibilities, selection) { match did_you_mean(&possibilities, selection) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, name.span)), Some(suggestion) => Err(ShellError::DidYouMean(suggestion, name.span)),
None => Err(ShellError::SpannedLabeledErrorHelp( None => Err(ShellError::GenericError(
"Operation not fount".into(), "Operation not fount".into(),
"Operation does not exist".into(), "Operation does not exist".into(),
name.span, Some(name.span),
"Perhaps you want: mean, sum, min, max, first, last, nunique, quantile, median, var, std, or count".into(), Some("Perhaps you want: mean, sum, min, max, first, last, nunique, quantile, median, var, std, or count".into()),
Vec::new(),
)) ))
} }
} }
@ -239,17 +244,21 @@ fn command(
None, None,
)) ))
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect datatype".into(), "Incorrect datatype".into(),
"no groupby or dataframe found in input stream".into(), "no groupby or dataframe found in input stream".into(),
call.head, Some(call.head),
None,
Vec::new(),
)), )),
} }
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect datatype".into(), "Incorrect datatype".into(),
"no groupby or dataframe found in input stream".into(), "no groupby or dataframe found in input stream".into(),
call.head, Some(call.head),
None,
Vec::new(),
)), )),
} }
} }
@ -283,7 +292,13 @@ fn perform_groupby_aggregation(
_ => operation_span, _ => operation_span,
}; };
ShellError::SpannedLabeledError("Error calculating aggregation".into(), e.to_string(), span) ShellError::GenericError(
"Error calculating aggregation".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
if !explicit { if !explicit {
@ -335,10 +350,12 @@ fn perform_dataframe_aggregation(
Operation::Quantile(quantile) => dataframe Operation::Quantile(quantile) => dataframe
.quantile(quantile, QuantileInterpolOptions::default()) .quantile(quantile, QuantileInterpolOptions::default())
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error calculating quantile".into(), "Error calculating quantile".into(),
e.to_string(), e.to_string(),
operation_span, Some(operation_span),
None,
Vec::new(),
) )
}), }),
Operation::Median => Ok(dataframe.median()), Operation::Median => Ok(dataframe.median()),
@ -358,11 +375,15 @@ fn perform_dataframe_aggregation(
match did_you_mean(&possibilities, operation.to_str()) { match did_you_mean(&possibilities, operation.to_str()) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, operation_span)), Some(suggestion) => Err(ShellError::DidYouMean(suggestion, operation_span)),
None => Err(ShellError::SpannedLabeledErrorHelp( None => Err(ShellError::GenericError(
"Operation not fount".into(), "Operation not fount".into(),
"Operation does not exist".into(), "Operation does not exist".into(),
operation_span, Some(operation_span),
"Perhaps you want: mean, sum, min, max, quantile, median, var, or std".into(), Some(
"Perhaps you want: mean, sum, min, max, quantile, median, var, or std"
.into(),
),
Vec::new(),
)), )),
} }
} }

View File

@ -62,7 +62,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let res = df.as_ref().column(&column.item).map_err(|e| { let res = df.as_ref().column(&column.item).map_err(|e| {
ShellError::SpannedLabeledError("Error selecting column".into(), e.to_string(), column.span) ShellError::GenericError(
"Error selecting column".into(),
e.to_string(),
Some(column.span),
None,
Vec::new(),
)
})?; })?;
NuDataFrame::try_from_series(vec![res.clone()], call.head) NuDataFrame::try_from_series(vec![res.clone()], call.head)

View File

@ -121,18 +121,22 @@ fn command(
if (&0.0..=&1.0).contains(&val) { if (&0.0..=&1.0).contains(&val) {
Ok(*val) Ok(*val)
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(), "Incorrect value for quantile".to_string(),
"value should be between 0 and 1".to_string(), "value should be between 0 and 1".to_string(),
*span, Some(*span),
None,
Vec::new(),
)) ))
} }
} }
_ => match value.span() { _ => match value.span() {
Ok(span) => Err(ShellError::SpannedLabeledError( Ok(span) => Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(), "Incorrect value for quantile".to_string(),
"value should be a float".to_string(), "value should be a float".to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
Err(e) => Err(e), Err(e) => Err(e),
}, },
@ -242,7 +246,13 @@ fn command(
DataFrame::new(res) DataFrame::new(res)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError("Dataframe Error".into(), e.to_string(), call.head) ShellError::GenericError(
"Dataframe Error".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
} }

View File

@ -66,18 +66,22 @@ fn command(
let new_df = col_string let new_df = col_string
.get(0) .get(0)
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Empty names list".into(), "Empty names list".into(),
"No column names where found".into(), "No column names where found".into(),
col_span, Some(col_span),
None,
Vec::new(),
) )
}) })
.and_then(|col| { .and_then(|col| {
df.as_ref().drop(&col.item).map_err(|e| { df.as_ref().drop(&col.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error dropping column".into(), "Error dropping column".into(),
e.to_string(), e.to_string(),
col.span, Some(col.span),
None,
Vec::new(),
) )
}) })
})?; })?;
@ -89,10 +93,12 @@ fn command(
.skip(1) .skip(1)
.try_fold(new_df, |new_df, col| { .try_fold(new_df, |new_df, col| {
new_df.drop(&col.item).map_err(|e| { new_df.drop(&col.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error dropping column".into(), "Error dropping column".into(),
e.to_string(), e.to_string(),
col.span, Some(col.span),
None,
Vec::new(),
) )
}) })
}) })

View File

@ -97,10 +97,12 @@ fn command(
df.as_ref() df.as_ref()
.distinct(subset_slice, keep_strategy) .distinct(subset_slice, keep_strategy)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error dropping duplicates".into(), "Error dropping duplicates".into(),
e.to_string(), e.to_string(),
col_span, Some(col_span),
None,
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -112,7 +112,13 @@ fn command(
df.as_ref() df.as_ref()
.drop_nulls(subset_slice) .drop_nulls(subset_slice)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError("Error dropping nulls".into(), e.to_string(), col_span) ShellError::GenericError(
"Error dropping nulls".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
} }

View File

@ -115,11 +115,12 @@ fn command(
df.as_ref() df.as_ref()
.to_dummies() .to_dummies()
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error calculating dummies".into(), "Error calculating dummies".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The only allowed column types for dummies are String or Int".into(), Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -63,11 +63,12 @@ fn command(
let mask_span = mask_value.span()?; let mask_span = mask_value.span()?;
let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?; let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?;
let mask = mask.bool().map_err(|e| { let mask = mask.bool().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to bool".into(), "Error casting to bool".into(),
e.to_string(), e.to_string(),
mask_span, Some(mask_span),
"Perhaps you want to use a series with booleans as mask".into(), Some("Perhaps you want to use a series with booleans as mask".into()),
Vec::new(),
) )
})?; })?;
@ -76,11 +77,12 @@ fn command(
df.as_ref() df.as_ref()
.filter(mask) .filter(mask)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error calculating dummies".into(), "Error calculating dummies".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The only allowed column types for dummies are String or Int".into(), Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -67,10 +67,12 @@ fn command(
df.as_ref() df.as_ref()
.select(&col_string) .select(&col_string)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error selecting columns".into(), "Error selecting columns".into(),
e.to_string(), e.to_string(),
col_span, Some(col_span),
None,
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -61,7 +61,13 @@ fn command(
// dataframe. Once it has been done these values can be stored // dataframe. Once it has been done these values can be stored
// in a NuGroupBy // in a NuGroupBy
let groupby = df.as_ref().groupby(&col_string).map_err(|e| { let groupby = df.as_ref().groupby(&col_string).map_err(|e| {
ShellError::SpannedLabeledError("Error creating groupby".into(), e.to_string(), col_span) ShellError::GenericError(
"Error creating groupby".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
})?; })?;
let groups = groupby.get_groups(); let groups = groupby.get_groups();

View File

@ -116,11 +116,12 @@ fn command(
"outer" => JoinType::Outer, "outer" => JoinType::Outer,
"left" => JoinType::Left, "left" => JoinType::Left,
_ => { _ => {
return Err(ShellError::SpannedLabeledErrorHelp( return Err(ShellError::GenericError(
"Incorrect join type".into(), "Incorrect join type".into(),
"Invalid join type".into(), "Invalid join type".into(),
val.span, Some(val.span),
"Options: inner, outer or left".into(), Some("Options: inner, outer or left".into()),
Vec::new(),
)) ))
} }
}, },
@ -150,10 +151,12 @@ fn command(
suffix, suffix,
) )
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error joining dataframes".into(), "Error joining dataframes".into(),
e.to_string(), e.to_string(),
l_col_span, Some(l_col_span),
None,
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
@ -168,45 +171,51 @@ fn check_column_datatypes<T: AsRef<str>>(
r_col_span: Span, r_col_span: Span,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
if l_cols.len() != r_cols.len() { if l_cols.len() != r_cols.len() {
return Err(ShellError::SpannedLabeledErrorHelp( return Err(ShellError::GenericError(
"Mismatched number of column names".into(), "Mismatched number of column names".into(),
format!( format!(
"found {} left names vs {} right names", "found {} left names vs {} right names",
l_cols.len(), l_cols.len(),
r_cols.len() r_cols.len()
), ),
l_col_span, Some(l_col_span),
"perhaps you need to change the number of columns to join".into(), Some("perhaps you need to change the number of columns to join".into()),
Vec::new(),
)); ));
} }
for (l, r) in l_cols.iter().zip(r_cols) { for (l, r) in l_cols.iter().zip(r_cols) {
let l_series = df_l.column(l.as_ref()).map_err(|e| { let l_series = df_l.column(l.as_ref()).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error selecting the columns".into(), "Error selecting the columns".into(),
e.to_string(), e.to_string(),
l_col_span, Some(l_col_span),
None,
Vec::new(),
) )
})?; })?;
let r_series = df_r.column(r.as_ref()).map_err(|e| { let r_series = df_r.column(r.as_ref()).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error selecting the columns".into(), "Error selecting the columns".into(),
e.to_string(), e.to_string(),
r_col_span, Some(r_col_span),
None,
Vec::new(),
) )
})?; })?;
if l_series.dtype() != r_series.dtype() { if l_series.dtype() != r_series.dtype() {
return Err(ShellError::SpannedLabeledErrorHelp( return Err(ShellError::GenericError(
"Mismatched datatypes".into(), "Mismatched datatypes".into(),
format!( format!(
"left column type '{}' doesn't match '{}' right column match", "left column type '{}' doesn't match '{}' right column match",
l_series.dtype(), l_series.dtype(),
r_series.dtype() r_series.dtype()
), ),
l_col_span, Some(l_col_span),
"perhaps you need to select other column to match".into(), Some("perhaps you need to select other column to match".into()),
Vec::new(),
)); ));
} }
} }

View File

@ -148,29 +148,35 @@ fn command(
.as_ref() .as_ref()
.melt(&id_col_string, &val_col_string) .melt(&id_col_string, &val_col_string)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error calculating melt".into(), "Error calculating melt".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;
if let Some(name) = &variable_name { if let Some(name) = &variable_name {
res.rename("variable", &name.item).map_err(|e| { res.rename("variable", &name.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error renaming column".into(), "Error renaming column".into(),
e.to_string(), e.to_string(),
name.span, Some(name.span),
None,
Vec::new(),
) )
})?; })?;
} }
if let Some(name) = &value_name { if let Some(name) = &value_name {
res.rename("value", &name.item).map_err(|e| { res.rename("value", &name.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error renaming column".into(), "Error renaming column".into(),
e.to_string(), e.to_string(),
name.span, Some(name.span),
None,
Vec::new(),
) )
})?; })?;
} }
@ -187,10 +193,12 @@ fn check_column_datatypes<T: AsRef<str>>(
col_span: Span, col_span: Span,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
if cols.is_empty() { if cols.is_empty() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Merge error".into(), "Merge error".into(),
"empty column list".into(), "empty column list".into(),
col_span, Some(col_span),
None,
Vec::new(),
)); ));
} }
@ -198,31 +206,36 @@ fn check_column_datatypes<T: AsRef<str>>(
if cols.len() > 1 { if cols.len() > 1 {
for w in cols.windows(2) { for w in cols.windows(2) {
let l_series = df.column(w[0].as_ref()).map_err(|e| { let l_series = df.column(w[0].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error selecting columns".into(), "Error selecting columns".into(),
e.to_string(), e.to_string(),
col_span, Some(col_span),
None,
Vec::new(),
) )
})?; })?;
let r_series = df.column(w[1].as_ref()).map_err(|e| { let r_series = df.column(w[1].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error selecting columns".into(), "Error selecting columns".into(),
e.to_string(), e.to_string(),
col_span, Some(col_span),
None,
Vec::new(),
) )
})?; })?;
if l_series.dtype() != r_series.dtype() { if l_series.dtype() != r_series.dtype() {
return Err(ShellError::SpannedLabeledErrorHelp( return Err(ShellError::GenericError(
"Merge error".into(), "Merge error".into(),
"found different column types in list".into(), "found different column types in list".into(),
col_span, Some(col_span),
format!( Some(format!(
"datatypes {} and {} are incompatible", "datatypes {} and {} are incompatible",
l_series.dtype(), l_series.dtype(),
r_series.dtype() r_series.dtype()
), )),
Vec::new(),
)); ));
} }
} }

View File

@ -115,7 +115,13 @@ fn from_parquet(
let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?; let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?;
let r = File::open(&file.item).map_err(|e| { let r = File::open(&file.item).map_err(|e| {
ShellError::SpannedLabeledError("Error opening file".into(), e.to_string(), file.span) ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
})?; })?;
let reader = ParquetReader::new(r); let reader = ParquetReader::new(r);
@ -125,10 +131,12 @@ fn from_parquet(
}; };
reader.finish().map_err(|e| { reader.finish().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Parquet reader error".into(), "Parquet reader error".into(),
format!("{:?}", e), format!("{:?}", e),
call.head, Some(call.head),
None,
Vec::new(),
) )
}) })
} }
@ -140,14 +148,26 @@ fn from_json(
) -> Result<polars::prelude::DataFrame, ShellError> { ) -> Result<polars::prelude::DataFrame, ShellError> {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?; let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let mut file = File::open(&file.item).map_err(|e| { let mut file = File::open(&file.item).map_err(|e| {
ShellError::SpannedLabeledError("Error opening file".into(), e.to_string(), file.span) ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
})?; })?;
let buf_reader = BufReader::new(&mut file); let buf_reader = BufReader::new(&mut file);
let reader = JsonReader::new(buf_reader); let reader = JsonReader::new(buf_reader);
reader.finish().map_err(|e| { reader.finish().map_err(|e| {
ShellError::SpannedLabeledError("Json reader error".into(), format!("{:?}", e), call.head) ShellError::GenericError(
"Json reader error".into(),
format!("{:?}", e),
Some(call.head),
None,
Vec::new(),
)
}) })
} }
@ -165,10 +185,12 @@ fn from_csv(
let csv_reader = CsvReader::from_path(&file.item) let csv_reader = CsvReader::from_path(&file.item)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating CSV reader".into(), "Error creating CSV reader".into(),
e.to_string(), e.to_string(),
file.span, Some(file.span),
None,
Vec::new(),
) )
})? })?
.with_encoding(CsvEncoding::LossyUtf8); .with_encoding(CsvEncoding::LossyUtf8);
@ -177,10 +199,12 @@ fn from_csv(
None => csv_reader, None => csv_reader,
Some(d) => { Some(d) => {
if d.item.len() != 1 { if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Incorrect delimiter".into(), "Incorrect delimiter".into(),
"Delimiter has to be one character".into(), "Delimiter has to be one character".into(),
d.span, Some(d.span),
None,
Vec::new(),
)); ));
} else { } else {
let delimiter = match d.item.chars().next() { let delimiter = match d.item.chars().next() {
@ -210,10 +234,12 @@ fn from_csv(
}; };
csv_reader.finish().map_err(|e| { csv_reader.finish().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Parquet reader error".into(), "Parquet reader error".into(),
format!("{:?}", e), format!("{:?}", e),
call.head, Some(call.head),
None,
Vec::new(),
) )
}) })
} }

View File

@ -28,11 +28,12 @@ impl Operation {
"max" => Ok(Operation::Max), "max" => Ok(Operation::Max),
"mean" => Ok(Operation::Mean), "mean" => Ok(Operation::Mean),
"median" => Ok(Operation::Median), "median" => Ok(Operation::Median),
_ => Err(ShellError::SpannedLabeledErrorHelp( _ => Err(ShellError::GenericError(
"Operation not fount".into(), "Operation not fount".into(),
"Operation does not exist for pivot".into(), "Operation does not exist for pivot".into(),
name.span, Some(name.span),
"Options: first, sum, min, max, mean, median".into(), Some("Options: first, sum, min, max, mean, median".into()),
Vec::new(),
)), )),
} }
} }
@ -116,7 +117,13 @@ fn command(
Operation::Median => pivot.median(), Operation::Median => pivot.median(),
} }
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError("Error creating pivot".into(), e.to_string(), call.head) ShellError::GenericError(
"Error creating pivot".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
} }
@ -126,7 +133,13 @@ fn check_pivot_column(
col: &Spanned<String>, col: &Spanned<String>,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
let series = df.column(&col.item).map_err(|e| { let series = df.column(&col.item).map_err(|e| {
ShellError::SpannedLabeledError("Column not found".into(), e.to_string(), col.span) ShellError::GenericError(
"Column not found".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})?; })?;
match series.dtype() { match series.dtype() {
@ -139,10 +152,12 @@ fn check_pivot_column(
| DataType::Int32 | DataType::Int32
| DataType::Int64 | DataType::Int64
| DataType::Utf8 => Ok(()), | DataType::Utf8 => Ok(()),
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Pivot error".into(), "Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()), format!("Unsupported datatype {}", series.dtype()),
col.span, Some(col.span),
None,
Vec::new(),
)), )),
} }
} }
@ -152,7 +167,13 @@ fn check_value_column(
col: &Spanned<String>, col: &Spanned<String>,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
let series = df.column(&col.item).map_err(|e| { let series = df.column(&col.item).map_err(|e| {
ShellError::SpannedLabeledError("Column not found".into(), e.to_string(), col.span) ShellError::GenericError(
"Column not found".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})?; })?;
match series.dtype() { match series.dtype() {
@ -166,10 +187,12 @@ fn check_value_column(
| DataType::Int64 | DataType::Int64
| DataType::Float32 | DataType::Float32
| DataType::Float64 => Ok(()), | DataType::Float64 => Ok(()),
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Pivot error".into(), "Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()), format!("Unsupported datatype {}", series.dtype()),
col.span, Some(col.span),
None,
Vec::new(),
)), )),
} }
} }

View File

@ -72,7 +72,13 @@ fn command(
df.as_mut() df.as_mut()
.rename(&from, &to) .rename(&from, &to)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError("Error renaming".into(), e.to_string(), call.head) ShellError::GenericError(
"Error renaming".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
}) })
.map(|df| { .map(|df| {
PipelineData::Value( PipelineData::Value(

View File

@ -77,29 +77,36 @@ fn command(
match (rows, fraction) { match (rows, fraction) {
(Some(rows), None) => df.as_ref().sample_n(rows.item, replace, 0).map_err(|e| { (Some(rows), None) => df.as_ref().sample_n(rows.item, replace, 0).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating sample".into(), "Error creating sample".into(),
e.to_string(), e.to_string(),
rows.span, Some(rows.span),
None,
Vec::new(),
) )
}), }),
(None, Some(frac)) => df.as_ref().sample_frac(frac.item, replace, 0).map_err(|e| { (None, Some(frac)) => df.as_ref().sample_frac(frac.item, replace, 0).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating sample".into(), "Error creating sample".into(),
e.to_string(), e.to_string(),
frac.span, Some(frac.span),
None,
Vec::new(),
) )
}), }),
(Some(_), Some(_)) => Err(ShellError::SpannedLabeledError( (Some(_), Some(_)) => Err(ShellError::GenericError(
"Incompatible flags".into(), "Incompatible flags".into(),
"Only one selection criterion allowed".into(), "Only one selection criterion allowed".into(),
call.head, Some(call.head),
None,
Vec::new(),
)), )),
(None, None) => Err(ShellError::SpannedLabeledErrorHelp( (None, None) => Err(ShellError::GenericError(
"No selection".into(), "No selection".into(),
"No selection criterion was found".into(), "No selection criterion was found".into(),
call.head, Some(call.head),
"Perhaps you want to use the flag -n or -f".into(), Some("Perhaps you want to use the flag -n or -f".into()),
Vec::new(),
)), )),
} }
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -95,10 +95,12 @@ fn command(
df.as_ref() df.as_ref()
.sort(columns, reverse) .sort(columns, reverse)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error sorting dataframe".into(), "Error sorting dataframe".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
@ -111,20 +113,24 @@ fn command(
df.as_ref() df.as_ref()
.sort(&col_string, reverse) .sort(&col_string, reverse)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error sorting dataframe".into(), "Error sorting dataframe".into(),
e.to_string(), e.to_string(),
col_span, Some(col_span),
None,
Vec::new(),
) )
}) })
.map(|df| { .map(|df| {
PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None) PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)
}) })
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Missing columns".into(), "Missing columns".into(),
"missing column name to perform sort".into(), "missing column name to perform sort".into(),
call.head, Some(call.head),
None,
Vec::new(),
)) ))
} }
} }

View File

@ -95,26 +95,31 @@ fn command(
let casted = match index.dtype() { let casted = match index.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => { DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
index.cast(&DataType::UInt32).map_err(|e| { index.cast(&DataType::UInt32).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting index list".into(), "Error casting index list".into(),
e.to_string(), e.to_string(),
index_span, Some(index_span),
None,
Vec::new(),
) )
}) })
} }
_ => Err(ShellError::SpannedLabeledErrorHelp( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
"Series with incorrect type".into(), "Series with incorrect type".into(),
call.head, Some(call.head),
"Consider using a Series with type int type".into(), Some("Consider using a Series with type int type".into()),
Vec::new(),
)), )),
}?; }?;
let indices = casted.u32().map_err(|e| { let indices = casted.u32().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting index list".into(), "Error casting index list".into(),
e.to_string(), e.to_string(),
index_span, Some(index_span),
None,
Vec::new(),
) )
})?; })?;
@ -122,10 +127,12 @@ fn command(
df.as_ref() df.as_ref()
.take(indices) .take(indices)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error taking values".into(), "Error taking values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
}) })
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)) .map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -74,10 +74,12 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?; let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let mut file = File::create(&file_name.item).map_err(|e| { let mut file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error with file name".into(), "Error with file name".into(),
e.to_string(), e.to_string(),
file_name.span, Some(file_name.span),
None,
Vec::new(),
) )
})?; })?;
@ -93,10 +95,12 @@ fn command(
None => writer, None => writer,
Some(d) => { Some(d) => {
if d.item.len() != 1 { if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Incorrect delimiter".into(), "Incorrect delimiter".into(),
"Delimiter has to be one char".into(), "Delimiter has to be one char".into(),
d.span, Some(d.span),
None,
Vec::new(),
)); ));
} else { } else {
let delimiter = match d.item.chars().next() { let delimiter = match d.item.chars().next() {
@ -110,10 +114,12 @@ fn command(
}; };
writer.finish(df.as_mut()).map_err(|e| { writer.finish(df.as_mut()).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error writing to file".into(), "Error writing to file".into(),
e.to_string(), e.to_string(),
file_name.span, Some(file_name.span),
None,
Vec::new(),
) )
})?; })?;

View File

@ -58,15 +58,23 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?; let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let file = File::create(&file_name.item).map_err(|e| { let file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error with file name".into(), "Error with file name".into(),
e.to_string(), e.to_string(),
file_name.span, Some(file_name.span),
None,
Vec::new(),
) )
})?; })?;
ParquetWriter::new(file).finish(df.as_mut()).map_err(|e| { ParquetWriter::new(file).finish(df.as_mut()).map_err(|e| {
ShellError::SpannedLabeledError("Error saving file".into(), e.to_string(), file_name.span) ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
})?; })?;
let file_value = Value::String { let file_value = Value::String {

View File

@ -83,10 +83,12 @@ fn command(
df.as_mut() df.as_mut()
.with_column(series) .with_column(series)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error adding column to dataframe".into(), "Error adding column to dataframe".into(),
e.to_string(), e.to_string(),
other_span, Some(other_span),
None,
Vec::new(),
) )
}) })
.map(|df| { .map(|df| {

View File

@ -74,10 +74,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| { let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error converting to bool".into(), "Error converting to bool".into(),
"all-false only works with series of type bool".into(), "all-false only works with series of type bool".into(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -74,10 +74,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| { let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error converting to bool".into(), "Error converting to bool".into(),
"all-false only works with series of type bool".into(), "all-false only works with series of type bool".into(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -20,11 +20,12 @@ impl CumType {
"min" => Ok(Self::Min), "min" => Ok(Self::Min),
"max" => Ok(Self::Max), "max" => Ok(Self::Max),
"sum" => Ok(Self::Sum), "sum" => Ok(Self::Sum),
_ => Err(ShellError::SpannedLabeledErrorHelp( _ => Err(ShellError::GenericError(
"Wrong operation".into(), "Wrong operation".into(),
"Operation not valid for cumulative".into(), "Operation not valid for cumulative".into(),
span, Some(span),
"Allowed values: max, min, sum".into(), Some("Allowed values: max, min, sum".into()),
Vec::new(),
)), )),
} }
} }
@ -102,10 +103,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() { if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Found object series".into(), "Found object series".into(),
"Series of type object cannot be used for cumulative operation".into(), "Series of type object cannot be used for cumulative operation".into(),
call.head, Some(call.head),
None,
Vec::new(),
)); ));
} }

View File

@ -65,7 +65,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| { let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to string".into(), e.to_string(), call.head) ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
let res = if not_exact { let res = if not_exact {
@ -76,10 +82,12 @@ fn command(
let mut res = res let mut res = res
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating datetime".into(), "Error creating datetime".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.into_series(); .into_series();

View File

@ -98,7 +98,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| { let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to string".into(), e.to_string(), call.head) ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
let res = if not_exact { let res = if not_exact {
@ -109,10 +115,12 @@ fn command(
let mut res = res let mut res = res
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating datetime".into(), "Error creating datetime".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.into_series(); .into_series();

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to datetime type".into(), "Error casting to datetime type".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -59,10 +59,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| { let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error converting to bool".into(), "Error converting to bool".into(),
"all-false only works with series of type bool".into(), "all-false only works with series of type bool".into(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -61,10 +61,12 @@ fn command(
.as_series(call.head)? .as_series(call.head)?
.arg_unique() .arg_unique()
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error extracting unique values".into(), "Error extracting unique values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.into_series(); .into_series();

View File

@ -84,28 +84,33 @@ fn command(
let casted = match indices.dtype() { let casted = match indices.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => { DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
indices.as_ref().cast(&DataType::UInt32).map_err(|e| { indices.as_ref().cast(&DataType::UInt32).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting indices".into(), "Error casting indices".into(),
e.to_string(), e.to_string(),
indices_span, Some(indices_span),
None,
Vec::new(),
) )
}) })
} }
_ => Err(ShellError::SpannedLabeledErrorHelp( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
"Series with incorrect type".into(), "Series with incorrect type".into(),
indices_span, Some(indices_span),
"Consider using a Series with type int type".into(), Some("Consider using a Series with type int type".into()),
Vec::new(),
)), )),
}?; }?;
let indices = casted let indices = casted
.u32() .u32()
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting indices".into(), "Error casting indices".into(),
e.to_string(), e.to_string(),
indices_span, Some(indices_span),
None,
Vec::new(),
) )
})? })?
.into_iter() .into_iter()
@ -117,42 +122,70 @@ fn command(
let res = match value { let res = match value {
Value::Int { val, span } => { Value::Int { val, span } => {
let chunked = series.i64().map_err(|e| { let chunked = series.i64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to i64".into(), e.to_string(), span) ShellError::GenericError(
"Error casting to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| { let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span) ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
Value::Float { val, span } => { Value::Float { val, span } => {
let chunked = series.as_ref().f64().map_err(|e| { let chunked = series.as_ref().f64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to f64".into(), e.to_string(), span) ShellError::GenericError(
"Error casting to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| { let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span) ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
Value::String { val, span } => { Value::String { val, span } => {
let chunked = series.as_ref().utf8().map_err(|e| { let chunked = series.as_ref().utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;
let res = chunked let res = chunked
.set_at_idx(indices, Some(val.as_ref())) .set_at_idx(indices, Some(val.as_ref()))
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error setting value".into(), "Error setting value".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;
@ -161,13 +194,15 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect value type".into(), "Incorrect value type".into(),
format!( format!(
"this value cannot be set in a series of type '{}'", "this value cannot be set in a series of type '{}'",
series.dtype() series.dtype()
), ),
value.span()?, Some(value.span()?),
None,
Vec::new(),
)), )),
}; };

View File

@ -69,10 +69,12 @@ fn command(
.as_series(call.head)? .as_series(call.head)?
.is_duplicated() .is_duplicated()
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error finding duplicates".into(), "Error finding duplicates".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.into_series(); .into_series();

View File

@ -78,10 +78,12 @@ fn command(
.as_series(call.head)? .as_series(call.head)?
.is_in(&other) .is_in(&other)
.map_err(|e| { .map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error finding in other".into(), "Error finding in other".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.into_series(); .into_series();

View File

@ -66,10 +66,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let mut res = df.as_series(call.head)?.is_unique().map_err(|e| { let mut res = df.as_series(call.head)?.is_unique().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error finding unique values".into(), "Error finding unique values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;
res.rename("is_unique"); res.rename("is_unique");

View File

@ -65,7 +65,13 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|e| { let bool = series.bool().map_err(|e| {
ShellError::SpannedLabeledError("Error inverting mask".into(), e.to_string(), call.head) ShellError::GenericError(
"Error inverting mask".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
let res = bool.not(); let res = bool.not();

View File

@ -82,16 +82,20 @@ fn command(
let bool_mask = match mask.dtype() { let bool_mask = match mask.dtype() {
DataType::Boolean => mask.bool().map_err(|e| { DataType::Boolean => mask.bool().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to bool".into(), "Error casting to bool".into(),
e.to_string(), e.to_string(),
mask_span, Some(mask_span),
None,
Vec::new(),
) )
}), }),
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
"can only use bool series as mask".into(), "can only use bool series as mask".into(),
mask_span, Some(mask_span),
None,
Vec::new(),
)), )),
}?; }?;
@ -101,37 +105,69 @@ fn command(
let res = match value { let res = match value {
Value::Int { val, span } => { Value::Int { val, span } => {
let chunked = series.i64().map_err(|e| { let chunked = series.i64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to i64".into(), e.to_string(), span) ShellError::GenericError(
"Error casting to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| { let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span) ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
Value::Float { val, span } => { Value::Float { val, span } => {
let chunked = series.as_ref().f64().map_err(|e| { let chunked = series.as_ref().f64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to f64".into(), e.to_string(), span) ShellError::GenericError(
"Error casting to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| { let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span) ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
Value::String { val, span } => { Value::String { val, span } => {
let chunked = series.as_ref().utf8().map_err(|e| { let chunked = series.as_ref().utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;
let res = chunked.set(bool_mask, Some(val.as_ref())).map_err(|e| { let res = chunked.set(bool_mask, Some(val.as_ref())).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span) ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
let mut res = res.into_series(); let mut res = res.into_series();
@ -139,13 +175,15 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head) NuDataFrame::try_from_series(vec![res.into_series()], call.head)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect value type".into(), "Incorrect value type".into(),
format!( format!(
"this value cannot be set in a series of type '{}'", "this value cannot be set in a series of type '{}'",
series.dtype() series.dtype()
), ),
value.span()?, Some(value.span()?),
None,
Vec::new(),
)), )),
}; };

View File

@ -57,10 +57,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let res = df.as_series(call.head)?.n_unique().map_err(|e| { let res = df.as_series(call.head)?.n_unique().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error counting unique values".into(), "Error counting unique values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -22,11 +22,12 @@ impl RollType {
"max" => Ok(Self::Max), "max" => Ok(Self::Max),
"sum" => Ok(Self::Sum), "sum" => Ok(Self::Sum),
"mean" => Ok(Self::Mean), "mean" => Ok(Self::Mean),
_ => Err(ShellError::SpannedLabeledErrorHelp( _ => Err(ShellError::GenericError(
"Wrong operation".into(), "Wrong operation".into(),
"Operation not valid for cumulative".into(), "Operation not valid for cumulative".into(),
span, Some(span),
"Allowed values: min, max, sum, mean".into(), Some("Allowed values: min, max, sum, mean".into()),
Vec::new(),
)), )),
} }
} }
@ -123,10 +124,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() { if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Found object series".into(), "Found object series".into(),
"Series of type object cannot be used for rolling operation".into(), "Series of type object cannot be used for rolling operation".into(),
call.head, Some(call.head),
None,
Vec::new(),
)); ));
} }
@ -146,10 +149,12 @@ fn command(
}; };
let mut res = res.map_err(|e| { let mut res = res.map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error calculating rolling values".into(), "Error calculating rolling values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -75,19 +75,23 @@ fn command(
let other_series = other_df.as_series(other_span)?; let other_series = other_df.as_series(other_span)?;
let other_chunked = other_series.utf8().map_err(|e| { let other_chunked = other_series.utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"The concatenate only with string columns".into(), "The concatenate only with string columns".into(),
e.to_string(), e.to_string(),
other_span, Some(other_span),
None,
Vec::new(),
) )
})?; })?;
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"The concatenate only with string columns".into(), "The concatenate only with string columns".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -71,18 +71,22 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"The contains command only with string columns".into(), "The contains command only with string columns".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;
let res = chunked.contains(&pattern).map_err(|e| { let res = chunked.contains(&pattern).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error searching in series".into(), "Error searching in series".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -83,18 +83,22 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error convertion to string".into(), "Error convertion to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;
let mut res = chunked.replace(&pattern, &replace).map_err(|e| { let mut res = chunked.replace(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error finding pattern other".into(), "Error finding pattern other".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -83,18 +83,22 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?; let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error convertion to string".into(), "Error convertion to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;
let mut res = chunked.replace_all(&pattern, &replace).map_err(|e| { let mut res = chunked.replace_all(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error finding pattern other".into(), "Error finding pattern other".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})?; })?;

View File

@ -59,11 +59,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-lengths command can only be used with string columns".into(), Some("The str-lengths command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -72,16 +72,23 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| { let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;
let mut res = chunked.str_slice(start, length).map_err(|e| { let mut res = chunked.str_slice(start, length).map_err(|e| {
ShellError::SpannedLabeledError("Error slicing series".into(), e.to_string(), call.head) ShellError::GenericError(
"Error slicing series".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
res.rename(series.name()); res.rename(series.name());

View File

@ -69,11 +69,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to date".into(), "Error casting to date".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -63,11 +63,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| { let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -63,11 +63,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| { let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error casting to string".into(), "Error casting to string".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -59,11 +59,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let res = series.unique().map_err(|e| { let res = series.unique().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error calculating unique values".into(), "Error calculating unique values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -64,11 +64,12 @@ fn command(
let series = df.as_series(call.head)?; let series = df.as_series(call.head)?;
let res = series.value_counts().map_err(|e| { let res = series.value_counts().map_err(|e| {
ShellError::SpannedLabeledErrorHelp( ShellError::GenericError(
"Error calculating value counts values".into(), "Error calculating value counts values".into(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
"The str-slice command can only be used with string columns".into(), Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
) )
})?; })?;

View File

@ -66,10 +66,12 @@ pub(super) fn compute_between_series(
res.rename(&name); res.rename(&name);
NuDataFrame::series_to_value(res, operation_span) NuDataFrame::series_to_value(res, operation_span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Division error".into(), "Division error".into(),
e.to_string(), e.to_string(),
right.span()?, Some(right.span()?),
None,
Vec::new(),
)), )),
} }
} }
@ -121,10 +123,12 @@ pub(super) fn compute_between_series(
res.rename(&name); res.rename(&name);
NuDataFrame::series_to_value(res, operation_span) NuDataFrame::series_to_value(res, operation_span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incompatible types".into(), "Incompatible types".into(),
"unable to cast to boolean".into(), "unable to cast to boolean".into(),
right.span()?, Some(right.span()?),
None,
Vec::new(),
)), )),
} }
} }
@ -148,10 +152,12 @@ pub(super) fn compute_between_series(
res.rename(&name); res.rename(&name);
NuDataFrame::series_to_value(res, operation_span) NuDataFrame::series_to_value(res, operation_span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incompatible types".into(), "Incompatible types".into(),
"unable to cast to boolean".into(), "unable to cast to boolean".into(),
right.span()?, Some(right.span()?),
None,
Vec::new(),
)), )),
} }
} }
@ -413,10 +419,12 @@ where
let casted = series.i64(); let casted = series.i64();
compute_casted_i64(casted, val, f, span) compute_casted_i64(casted, val, f, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(), "Unable to cast to i64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -424,13 +432,15 @@ where
let casted = series.i64(); let casted = series.i64();
compute_casted_i64(casted, val, f, span) compute_casted_i64(casted, val, f, span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
format!( format!(
"Series of type {} can not be used for operations with an i64 value", "Series of type {} can not be used for operations with an i64 value",
series.dtype() series.dtype()
), ),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -450,10 +460,12 @@ where
let res = res.into_series(); let res = res.into_series();
NuDataFrame::series_to_value(res, span) NuDataFrame::series_to_value(res, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(), "Unable to cast to i64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -476,10 +488,12 @@ where
let casted = series.f64(); let casted = series.f64();
compute_casted_f64(casted, val, f, span) compute_casted_f64(casted, val, f, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(), "Unable to cast to f64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -487,13 +501,15 @@ where
let casted = series.f64(); let casted = series.f64();
compute_casted_f64(casted, val, f, span) compute_casted_f64(casted, val, f, span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
format!( format!(
"Series of type {} can not be used for operations with a decimal value", "Series of type {} can not be used for operations with a decimal value",
series.dtype() series.dtype()
), ),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -513,10 +529,12 @@ where
let res = res.into_series(); let res = res.into_series();
NuDataFrame::series_to_value(res, span) NuDataFrame::series_to_value(res, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(), "Unable to cast to f64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -537,10 +555,12 @@ where
let casted = series.i64(); let casted = series.i64();
compare_casted_i64(casted, val, f, span) compare_casted_i64(casted, val, f, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(), "Unable to cast to f64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -556,10 +576,12 @@ where
.expect("already checked for casting"); .expect("already checked for casting");
compare_casted_i64(Ok(&casted), val, f, span) compare_casted_i64(Ok(&casted), val, f, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(), "Unable to cast to f64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -567,13 +589,15 @@ where
let casted = series.i64(); let casted = series.i64();
compare_casted_i64(casted, val, f, span) compare_casted_i64(casted, val, f, span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
format!( format!(
"Series of type {} can not be used for operations with an i64 value", "Series of type {} can not be used for operations with an i64 value",
series.dtype() series.dtype()
), ),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -593,10 +617,12 @@ where
let res = res.into_series(); let res = res.into_series();
NuDataFrame::series_to_value(res, span) NuDataFrame::series_to_value(res, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(), "Unable to cast to i64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -619,10 +645,12 @@ where
let casted = series.f64(); let casted = series.f64();
compare_casted_f64(casted, val, f, span) compare_casted_f64(casted, val, f, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(), "Unable to cast to i64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -630,13 +658,15 @@ where
let casted = series.f64(); let casted = series.f64();
compare_casted_f64(casted, val, f, span) compare_casted_f64(casted, val, f, span)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect type".into(), "Incorrect type".into(),
format!( format!(
"Series of type {} can not be used for operations with a decimal value", "Series of type {} can not be used for operations with a decimal value",
series.dtype() series.dtype()
), ),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -656,10 +686,12 @@ where
let res = res.into_series(); let res = res.into_series();
NuDataFrame::series_to_value(res, span) NuDataFrame::series_to_value(res, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(), "Unable to cast to f64".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -675,17 +707,21 @@ fn contains_series_pat(series: &Series, pat: &str, span: Span) -> Result<Value,
let res = res.into_series(); let res = res.into_series();
NuDataFrame::series_to_value(res, span) NuDataFrame::series_to_value(res, span)
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Error using contains".into(), "Error using contains".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Unable to cast to string".into(), "Unable to cast to string".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }

View File

@ -122,7 +122,13 @@ pub fn create_column(
} }
DataType::UInt8 => { DataType::UInt8 => {
let casted = series.u8().map_err(|e| { let casted = series.u8().map_err(|e| {
ShellError::LabeledError("Error casting column to u8".into(), e.to_string()) ShellError::GenericError(
"Error casting column to u8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -141,7 +147,13 @@ pub fn create_column(
} }
DataType::UInt16 => { DataType::UInt16 => {
let casted = series.u16().map_err(|e| { let casted = series.u16().map_err(|e| {
ShellError::LabeledError("Error casting column to u16".into(), e.to_string()) ShellError::GenericError(
"Error casting column to u16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -160,7 +172,13 @@ pub fn create_column(
} }
DataType::UInt32 => { DataType::UInt32 => {
let casted = series.u32().map_err(|e| { let casted = series.u32().map_err(|e| {
ShellError::LabeledError("Error casting column to u32".into(), e.to_string()) ShellError::GenericError(
"Error casting column to u32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -179,7 +197,13 @@ pub fn create_column(
} }
DataType::UInt64 => { DataType::UInt64 => {
let casted = series.u64().map_err(|e| { let casted = series.u64().map_err(|e| {
ShellError::LabeledError("Error casting column to u64".into(), e.to_string()) ShellError::GenericError(
"Error casting column to u64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -198,7 +222,13 @@ pub fn create_column(
} }
DataType::Int8 => { DataType::Int8 => {
let casted = series.i8().map_err(|e| { let casted = series.i8().map_err(|e| {
ShellError::LabeledError("Error casting column to i8".into(), e.to_string()) ShellError::GenericError(
"Error casting column to i8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -217,7 +247,13 @@ pub fn create_column(
} }
DataType::Int16 => { DataType::Int16 => {
let casted = series.i16().map_err(|e| { let casted = series.i16().map_err(|e| {
ShellError::LabeledError("Error casting column to i16".into(), e.to_string()) ShellError::GenericError(
"Error casting column to i16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -236,7 +272,13 @@ pub fn create_column(
} }
DataType::Int32 => { DataType::Int32 => {
let casted = series.i32().map_err(|e| { let casted = series.i32().map_err(|e| {
ShellError::LabeledError("Error casting column to i32".into(), e.to_string()) ShellError::GenericError(
"Error casting column to i32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -255,7 +297,13 @@ pub fn create_column(
} }
DataType::Int64 => { DataType::Int64 => {
let casted = series.i64().map_err(|e| { let casted = series.i64().map_err(|e| {
ShellError::LabeledError("Error casting column to i64".into(), e.to_string()) ShellError::GenericError(
"Error casting column to i64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -274,7 +322,13 @@ pub fn create_column(
} }
DataType::Float32 => { DataType::Float32 => {
let casted = series.f32().map_err(|e| { let casted = series.f32().map_err(|e| {
ShellError::LabeledError("Error casting column to f32".into(), e.to_string()) ShellError::GenericError(
"Error casting column to f32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -293,7 +347,13 @@ pub fn create_column(
} }
DataType::Float64 => { DataType::Float64 => {
let casted = series.f64().map_err(|e| { let casted = series.f64().map_err(|e| {
ShellError::LabeledError("Error casting column to f64".into(), e.to_string()) ShellError::GenericError(
"Error casting column to f64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
.into_iter() .into_iter()
@ -309,7 +369,13 @@ pub fn create_column(
} }
DataType::Boolean => { DataType::Boolean => {
let casted = series.bool().map_err(|e| { let casted = series.bool().map_err(|e| {
ShellError::LabeledError("Error casting column to bool".into(), e.to_string()) ShellError::GenericError(
"Error casting column to bool".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
@ -326,7 +392,13 @@ pub fn create_column(
} }
DataType::Utf8 => { DataType::Utf8 => {
let casted = series.utf8().map_err(|e| { let casted = series.utf8().map_err(|e| {
ShellError::LabeledError("Error casting column to string".into(), e.to_string()) ShellError::GenericError(
"Error casting column to string".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
@ -350,9 +422,12 @@ pub fn create_column(
.downcast_ref::<ChunkedArray<ObjectType<DataFrameValue>>>(); .downcast_ref::<ChunkedArray<ObjectType<DataFrameValue>>>();
match casted { match casted {
None => Err(ShellError::LabeledError( None => Err(ShellError::GenericError(
"Error casting object from series".into(), "Error casting object from series".into(),
format!("Object not supported for conversion: {}", x), "".to_string(),
None,
Some(format!("Object not supported for conversion: {}", x)),
Vec::new(),
)), )),
Some(ca) => { Some(ca) => {
let values = ca let values = ca
@ -371,7 +446,13 @@ pub fn create_column(
} }
DataType::Date => { DataType::Date => {
let casted = series.date().map_err(|e| { let casted = series.date().map_err(|e| {
ShellError::LabeledError("Error casting column to date".into(), e.to_string()) ShellError::GenericError(
"Error casting column to date".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
@ -401,7 +482,13 @@ pub fn create_column(
} }
DataType::Datetime(_, _) => { DataType::Datetime(_, _) => {
let casted = series.datetime().map_err(|e| { let casted = series.datetime().map_err(|e| {
ShellError::LabeledError("Error casting column to datetime".into(), e.to_string()) ShellError::GenericError(
"Error casting column to datetime".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
@ -431,7 +518,13 @@ pub fn create_column(
} }
DataType::Time => { DataType::Time => {
let casted = series.timestamp(TimeUnit::Nanoseconds).map_err(|e| { let casted = series.timestamp(TimeUnit::Nanoseconds).map_err(|e| {
ShellError::LabeledError("Error casting column to time".into(), e.to_string()) ShellError::GenericError(
"Error casting column to time".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
let values = casted let values = casted
@ -449,9 +542,12 @@ pub fn create_column(
Ok(Column::new(casted.name().into(), values)) Ok(Column::new(casted.name().into(), values))
} }
e => Err(ShellError::LabeledError( e => Err(ShellError::GenericError(
"Error creating Dataframe".into(), "Error creating Dataframe".into(),
format!("Value not supported in nushell: {}", e), "".to_string(),
None,
Some(format!("Value not supported in nushell: {}", e)),
Vec::new(),
)), )),
} }
} }
@ -620,5 +716,13 @@ pub fn from_parsed_columns(column_values: ColumnMap) -> Result<NuDataFrame, Shel
DataFrame::new(df_series) DataFrame::new(df_series)
.map(NuDataFrame::new) .map(NuDataFrame::new)
.map_err(|e| ShellError::LabeledError("Error creating dataframe".into(), e.to_string())) .map_err(|e| {
ShellError::GenericError(
"Error creating dataframe".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})
} }

View File

@ -111,10 +111,12 @@ impl NuDataFrame {
pub fn series_to_value(series: Series, span: Span) -> Result<Value, ShellError> { pub fn series_to_value(series: Series, span: Span) -> Result<Value, ShellError> {
match DataFrame::new(vec![series]) { match DataFrame::new(vec![series]) {
Ok(dataframe) => Ok(NuDataFrame::dataframe_into_value(dataframe, span)), Ok(dataframe) => Ok(NuDataFrame::dataframe_into_value(dataframe, span)),
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
"Error creating dataframe".into(), "Error creating dataframe".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
)), )),
} }
} }
@ -152,10 +154,12 @@ impl NuDataFrame {
pub fn try_from_series(columns: Vec<Series>, span: Span) -> Result<Self, ShellError> { pub fn try_from_series(columns: Vec<Series>, span: Span) -> Result<Self, ShellError> {
let dataframe = DataFrame::new(columns).map_err(|e| { let dataframe = DataFrame::new(columns).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating dataframe".into(), "Error creating dataframe".into(),
format!("Unable to create DataFrame: {}", e), format!("Unable to create DataFrame: {}", e),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;
@ -183,12 +187,14 @@ impl NuDataFrame {
"dataframe".into(), "dataframe".into(),
"non-dataframe".into(), "non-dataframe".into(),
span, span,
None,
)), )),
}, },
x => Err(ShellError::CantConvert( x => Err(ShellError::CantConvert(
"dataframe".into(), "dataframe".into(),
x.get_type().to_string(), x.get_type().to_string(),
x.span()?, x.span()?,
None,
)), )),
} }
} }
@ -212,7 +218,13 @@ impl NuDataFrame {
})?; })?;
let dataframe = DataFrame::new(vec![s.clone()]).map_err(|e| { let dataframe = DataFrame::new(vec![s.clone()]).map_err(|e| {
ShellError::SpannedLabeledError("Error creating dataframe".into(), e.to_string(), span) ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?; })?;
Ok(Self(dataframe)) Ok(Self(dataframe))
@ -224,10 +236,12 @@ impl NuDataFrame {
pub fn as_series(&self, span: Span) -> Result<Series, ShellError> { pub fn as_series(&self, span: Span) -> Result<Series, ShellError> {
if !self.is_series() { if !self.is_series() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Error using as series".into(), "Error using as series".into(),
"dataframe has more than one column".into(), "dataframe has more than one column".into(),
span, Some(span),
None,
Vec::new(),
)); ));
} }

View File

@ -138,10 +138,12 @@ impl NuDataFrame {
.collect::<Vec<Series>>(); .collect::<Vec<Series>>();
let df_new = DataFrame::new(new_cols).map_err(|e| { let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error creating dataframe".into(), "Error creating dataframe".into(),
e.to_string(), e.to_string(),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;
@ -183,10 +185,12 @@ impl NuDataFrame {
match res { match res {
Ok(s) => Ok(s.clone()), Ok(s) => Ok(s.clone()),
Err(e) => Err({ Err(e) => Err({
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error appending dataframe".into(), "Error appending dataframe".into(),
format!("Unable to append: {}", e), format!("Unable to append: {}", e),
span, Some(span),
None,
Vec::new(),
) )
}), }),
} }
@ -194,10 +198,12 @@ impl NuDataFrame {
.collect::<Result<Vec<Series>, ShellError>>()?; .collect::<Result<Vec<Series>, ShellError>>()?;
let df_new = DataFrame::new(new_cols).map_err(|e| { let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error appending dataframe".into(), "Error appending dataframe".into(),
format!("Unable to append dataframes: {}", e), format!("Unable to append dataframes: {}", e),
span, Some(span),
None,
Vec::new(),
) )
})?; })?;

View File

@ -78,12 +78,14 @@ impl NuGroupBy {
"groupby".into(), "groupby".into(),
"non-dataframe".into(), "non-dataframe".into(),
span, span,
None,
)), )),
}, },
x => Err(ShellError::CantConvert( x => Err(ShellError::CantConvert(
"groupby".into(), "groupby".into(),
x.get_type().to_string(), x.get_type().to_string(),
x.span()?, x.span()?,
None,
)), )),
} }
} }
@ -95,7 +97,13 @@ impl NuGroupBy {
pub fn to_groupby(&self) -> Result<GroupBy, ShellError> { pub fn to_groupby(&self) -> Result<GroupBy, ShellError> {
let by = self.dataframe.select_series(&self.by).map_err(|e| { let by = self.dataframe.select_series(&self.by).map_err(|e| {
ShellError::LabeledError("Error creating groupby".into(), e.to_string()) ShellError::GenericError(
"Error creating groupby".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?; })?;
Ok(GroupBy::new( Ok(GroupBy::new(

View File

@ -13,10 +13,12 @@ pub(crate) fn convert_columns(
let mut col_span = columns let mut col_span = columns
.get(0) .get(0)
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Empty column list".into(), "Empty column list".into(),
"Empty list found for command".into(), "Empty list found for command".into(),
span, Some(span),
None,
Vec::new(),
) )
}) })
.and_then(|v| v.span())?; .and_then(|v| v.span())?;
@ -28,10 +30,12 @@ pub(crate) fn convert_columns(
col_span = span_join(&[col_span, span]); col_span = span_join(&[col_span, span]);
Ok(Spanned { item: val, span }) Ok(Spanned { item: val, span })
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect column format".into(), "Incorrect column format".into(),
"Only string as column name".into(), "Only string as column name".into(),
span, Some(span),
None,
Vec::new(),
)), )),
}) })
.collect::<Result<Vec<Spanned<String>>, _>>()?; .collect::<Result<Vec<Spanned<String>>, _>>()?;
@ -49,10 +53,12 @@ pub(crate) fn convert_columns_string(
let mut col_span = columns let mut col_span = columns
.get(0) .get(0)
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Empty column list".into(), "Empty column list".into(),
"Empty list found for command".into(), "Empty list found for command".into(),
span, Some(span),
None,
Vec::new(),
) )
}) })
.and_then(|v| v.span())?; .and_then(|v| v.span())?;
@ -64,10 +70,12 @@ pub(crate) fn convert_columns_string(
col_span = span_join(&[col_span, span]); col_span = span_join(&[col_span, span]);
Ok(val) Ok(val)
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Incorrect column format".into(), "Incorrect column format".into(),
"Only string as column name".into(), "Only string as column name".into(),
span, Some(span),
None,
Vec::new(),
)), )),
}) })
.collect::<Result<Vec<String>, _>>()?; .collect::<Result<Vec<String>, _>>()?;

View File

@ -102,6 +102,7 @@ fn with_env(
call.positional_nth(1) call.positional_nth(1)
.expect("already checked through .req") .expect("already checked through .req")
.span, .span,
None,
)); ));
} }
} }
@ -128,6 +129,7 @@ fn with_env(
call.positional_nth(1) call.positional_nth(1)
.expect("already checked through .req") .expect("already checked through .req")
.span, .span,
None,
)); ));
} }
}; };

View File

@ -57,17 +57,21 @@ impl Command for ViewSource {
Ok(Value::string(String::from_utf8_lossy(contents), call.head) Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data()) .into_pipeline_data())
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Cannot view value".to_string(), "Cannot view value".to_string(),
"the command does not have a viewable block".to_string(), "the command does not have a viewable block".to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)) ))
} }
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Cannot view value".to_string(), "Cannot view value".to_string(),
"the command does not have a viewable block".to_string(), "the command does not have a viewable block".to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)) ))
} }
} else if let Some(overlay_id) = engine_state.find_overlay(val.as_bytes()) { } else if let Some(overlay_id) = engine_state.find_overlay(val.as_bytes()) {
@ -78,24 +82,30 @@ impl Command for ViewSource {
Ok(Value::string(String::from_utf8_lossy(contents), call.head) Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data()) .into_pipeline_data())
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Cannot view value".to_string(), "Cannot view value".to_string(),
"the module does not have a viewable block".to_string(), "the module does not have a viewable block".to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)) ))
} }
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Cannot view value".to_string(), "Cannot view value".to_string(),
"this name does not correspond to a viewable value".to_string(), "this name does not correspond to a viewable value".to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)) ))
} }
} }
_ => Err(ShellError::SpannedLabeledError( _ => Err(ShellError::GenericError(
"Cannot view value".to_string(), "Cannot view value".to_string(),
"this value cannot be viewed".to_string(), "this value cannot be viewed".to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)), )),
} }
} }

View File

@ -46,9 +46,9 @@ impl Command for Cd {
let path = match nu_path::canonicalize_with(path, &cwd) { let path = match nu_path::canonicalize_with(path, &cwd) {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
return Err(ShellError::DirectoryNotFoundHelp( return Err(ShellError::DirectoryNotFound(
*span, *span,
format!("IO Error: {:?}", e), Some(format!("IO Error: {:?}", e)),
)) ))
} }
}; };
@ -69,9 +69,9 @@ impl Command for Cd {
} }
Err(e) => { Err(e) => {
return Err(ShellError::DirectoryNotFoundHelp( return Err(ShellError::DirectoryNotFound(
v.span()?, v.span()?,
format!("IO Error: {:?}", e), Some(format!("IO Error: {:?}", e)),
)) ))
} }
}; };

View File

@ -61,37 +61,45 @@ impl Command for Cp {
let sources: Vec<_> = match nu_glob::glob_with(&source.to_string_lossy(), GLOB_PARAMS) { let sources: Vec<_> = match nu_glob::glob_with(&source.to_string_lossy(), GLOB_PARAMS) {
Ok(files) => files.collect(), Ok(files) => files.collect(),
Err(e) => { Err(e) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
e.to_string(), e.to_string(),
"invalid pattern".to_string(), "invalid pattern".to_string(),
src.span, Some(src.span),
None,
Vec::new(),
)) ))
} }
}; };
if sources.is_empty() { if sources.is_empty() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"No matches found".into(), "No matches found".into(),
"no matches found".into(), "no matches found".into(),
src.span, Some(src.span),
None,
Vec::new(),
)); ));
} }
if sources.len() > 1 && !destination.is_dir() { if sources.len() > 1 && !destination.is_dir() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Destination must be a directory when copying multiple files".into(), "Destination must be a directory when copying multiple files".into(),
"is not a directory".into(), "is not a directory".into(),
dst.span, Some(dst.span),
None,
Vec::new(),
)); ));
} }
let any_source_is_dir = sources.iter().any(|f| matches!(f, Ok(f) if f.is_dir())); let any_source_is_dir = sources.iter().any(|f| matches!(f, Ok(f) if f.is_dir()));
if any_source_is_dir && !recursive { if any_source_is_dir && !recursive {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Directories must be copied using \"--recursive\"".into(), "Directories must be copied using \"--recursive\"".into(),
"resolves to a directory (not copied)".into(), "resolves to a directory (not copied)".into(),
src.span, Some(src.span),
None,
Vec::new(),
)); ));
} }
@ -115,7 +123,13 @@ impl Command for Cp {
for (src, dst) in sources { for (src, dst) in sources {
if src.is_file() { if src.is_file() {
std::fs::copy(src, dst).map_err(|e| { std::fs::copy(src, dst).map_err(|e| {
ShellError::SpannedLabeledError(e.to_string(), e.to_string(), call.head) ShellError::GenericError(
e.to_string(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
} }
} }
@ -126,17 +140,25 @@ impl Command for Cp {
match entry.file_name() { match entry.file_name() {
Some(name) => destination.join(name), Some(name) => destination.join(name),
None => { None => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Copy aborted. Not a valid path".into(), "Copy aborted. Not a valid path".into(),
"not a valid path".into(), "not a valid path".into(),
dst.span, Some(dst.span),
None,
Vec::new(),
)) ))
} }
} }
}; };
std::fs::create_dir_all(&destination).map_err(|e| { std::fs::create_dir_all(&destination).map_err(|e| {
ShellError::SpannedLabeledError(e.to_string(), e.to_string(), dst.span) ShellError::GenericError(
e.to_string(),
e.to_string(),
Some(dst.span),
None,
Vec::new(),
)
})?; })?;
let sources = sources.paths_applying_with(|(source_file, depth_level)| { let sources = sources.paths_applying_with(|(source_file, depth_level)| {
@ -161,13 +183,25 @@ impl Command for Cp {
for (s, d) in sources { for (s, d) in sources {
if s.is_dir() && !d.exists() { if s.is_dir() && !d.exists() {
std::fs::create_dir_all(&d).map_err(|e| { std::fs::create_dir_all(&d).map_err(|e| {
ShellError::SpannedLabeledError(e.to_string(), e.to_string(), dst.span) ShellError::GenericError(
e.to_string(),
e.to_string(),
Some(dst.span),
None,
Vec::new(),
)
})?; })?;
} }
if s.is_file() { if s.is_file() {
std::fs::copy(&s, &d).map_err(|e| { std::fs::copy(&s, &d).map_err(|e| {
ShellError::SpannedLabeledError(e.to_string(), e.to_string(), call.head) ShellError::GenericError(
e.to_string(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?; })?;
} }
} }

View File

@ -104,9 +104,12 @@ impl Command for Glob {
let glob = match WaxGlob::new(&glob_pattern.item) { let glob = match WaxGlob::new(&glob_pattern.item) {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
return Err(ShellError::LabeledError( return Err(ShellError::GenericError(
"error with glob pattern".to_string(), "error with glob pattern".to_string(),
format!("{}", e), "".to_string(),
None,
Some(format!("{}", e)),
Vec::new(),
)) ))
} }
}; };

View File

@ -96,10 +96,12 @@ impl Command for Ls {
); );
#[cfg(not(unix))] #[cfg(not(unix))]
let error_msg = String::from("Permission denied"); let error_msg = String::from("Permission denied");
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Permission denied".to_string(), "Permission denied".to_string(),
error_msg, error_msg,
p_tag, Some(p_tag),
None,
Vec::new(),
)); ));
} }
if is_empty_dir(&expanded) { if is_empty_dir(&expanded) {
@ -129,9 +131,12 @@ impl Command for Ls {
let mut paths_peek = paths.peekable(); let mut paths_peek = paths.peekable();
if paths_peek.peek().is_none() { if paths_peek.peek().is_none() {
return Err(ShellError::LabeledError( return Err(ShellError::GenericError(
format!("No matches found for {}", &path.display().to_string()), format!("No matches found for {}", &path.display().to_string()),
"no matches found".to_string(), "".to_string(),
None,
Some("no matches found".to_string()),
Vec::new(),
)); ));
} }
@ -176,10 +181,12 @@ impl Command for Ls {
Some(path.to_string_lossy().to_string()) Some(path.to_string_lossy().to_string())
} }
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
format!("Invalid file name: {:}", path.to_string_lossy()), format!("Invalid file name: {:}", path.to_string_lossy()),
"invalid file name".into(), "invalid file name".into(),
call_span, Some(call_span),
None,
Vec::new(),
) )
}); });

View File

@ -71,10 +71,12 @@ impl Command for Mv {
.map_or_else(|_| Vec::new(), Iterator::collect); .map_or_else(|_| Vec::new(), Iterator::collect);
if sources.is_empty() { if sources.is_empty() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Invalid file or pattern".into(), "Invalid file or pattern".into(),
"invalid file or pattern".into(), "invalid file or pattern".into(),
spanned_source.span, Some(spanned_source.span),
None,
Vec::new(),
)); ));
} }
@ -91,10 +93,12 @@ impl Command for Mv {
if (destination.exists() && !destination.is_dir() && sources.len() > 1) if (destination.exists() && !destination.is_dir() && sources.len() > 1)
|| (!destination.exists() && sources.len() > 1) || (!destination.exists() && sources.len() > 1)
{ {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Can only move multiple sources if destination is a directory".into(), "Can only move multiple sources if destination is a directory".into(),
"destination must be a directory when multiple sources".into(), "destination must be a directory when multiple sources".into(),
spanned_destination.span, Some(spanned_destination.span),
None,
Vec::new(),
)); ));
} }
@ -103,13 +107,15 @@ impl Command for Mv {
.find(|f| matches!(f, Ok(f) if destination.starts_with(f))); .find(|f| matches!(f, Ok(f) if destination.starts_with(f)));
if destination.exists() && destination.is_dir() && sources.len() == 1 { if destination.exists() && destination.is_dir() && sources.len() == 1 {
if let Some(Ok(filename)) = some_if_source_is_destination { if let Some(Ok(filename)) = some_if_source_is_destination {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
format!( format!(
"Not possible to move {:?} to itself", "Not possible to move {:?} to itself",
filename.file_name().expect("Invalid file name") filename.file_name().expect("Invalid file name")
), ),
"cannot move to itself".into(), "cannot move to itself".into(),
spanned_destination.span, Some(spanned_destination.span),
None,
Vec::new(),
)); ));
} }
} }
@ -202,14 +208,14 @@ fn move_file(
}; };
if !destination_dir_exists { if !destination_dir_exists {
return Err(ShellError::DirectoryNotFound(to_span)); return Err(ShellError::DirectoryNotFound(to_span, None));
} }
let mut to = to; let mut to = to;
if to.is_dir() { if to.is_dir() {
let from_file_name = match from.file_name() { let from_file_name = match from.file_name() {
Some(name) => name, Some(name) => name,
None => return Err(ShellError::DirectoryNotFound(to_span)), None => return Err(ShellError::DirectoryNotFound(to_span, None)),
}; };
to.push(from_file_name); to.push(from_file_name);
@ -233,10 +239,12 @@ fn move_item(from: &Path, from_span: Span, to: &Path) -> Result<(), ShellError>
fs_extra::dir::move_dir(from, to, &options) fs_extra::dir::move_dir(from, to, &options)
} { } {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(e) => Err(ShellError::SpannedLabeledError( Err(e) => Err(ShellError::GenericError(
format!("Could not move {:?} to {:?}. {:}", from, to, e), format!("Could not move {:?} to {:?}. {:}", from, to, e),
"could not move".into(), "could not move".into(),
from_span, Some(from_span),
None,
Vec::new(),
)), )),
} }
}) })

View File

@ -94,19 +94,23 @@ impl Command for Open {
); );
#[cfg(not(unix))] #[cfg(not(unix))]
let error_msg = String::from("Permission denied"); let error_msg = String::from("Permission denied");
Err(ShellError::SpannedLabeledError( Err(ShellError::GenericError(
"Permission denied".into(), "Permission denied".into(),
error_msg, error_msg,
arg_span, Some(arg_span),
None,
Vec::new(),
)) ))
} else { } else {
let mut file = match std::fs::File::open(path) { let mut file = match std::fs::File::open(path) {
Ok(file) => file, Ok(file) => file,
Err(err) => { Err(err) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Permission denied".into(), "Permission denied".into(),
err.to_string(), err.to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
)); ));
} }
}; };
@ -198,16 +202,20 @@ fn open_and_read_sqlite_db(path: &Path, call_span: Span) -> Result<Value, nu_pro
match Connection::open(path) { match Connection::open(path) {
Ok(conn) => match read_sqlite_db(conn, call_span) { Ok(conn) => match read_sqlite_db(conn, call_span) {
Ok(data) => Ok(data), Ok(data) => Ok(data),
Err(err) => Err(ShellError::SpannedLabeledError( Err(err) => Err(ShellError::GenericError(
"Failed to read from SQLite database".into(), "Failed to read from SQLite database".into(),
err.to_string(), err.to_string(),
call_span, Some(call_span),
None,
Vec::new(),
)), )),
}, },
Err(err) => Err(ShellError::SpannedLabeledError( Err(err) => Err(ShellError::GenericError(
"Failed to open SQLite database".into(), "Failed to open SQLite database".into(),
err.to_string(), err.to_string(),
call_span, Some(call_span),
None,
Vec::new(),
)), )),
} }
} }

View File

@ -144,32 +144,38 @@ fn rm(
))] ))]
{ {
if rm_always_trash { if rm_always_trash {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot execute `rm`; the current configuration specifies \ "Cannot execute `rm`; the current configuration specifies \
`rm_always_trash = true`, but the current nu executable was not \ `rm_always_trash = true`, but the current nu executable was not \
built with feature `trash_support` or trash is not supported on \ built with feature `trash_support` or trash is not supported on \
your platform." your platform."
.into(), .into(),
"trash required to be true but not supported".into(), "trash required to be true but not supported".into(),
span, Some(span),
None,
Vec::new(),
)); ));
} else if trash { } else if trash {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot execute `rm` with option `--trash`; feature `trash-support` not \ "Cannot execute `rm` with option `--trash`; feature `trash-support` not \
enabled or trash is not supported on your platform" enabled or trash is not supported on your platform"
.into(), .into(),
"this option is only available if nu is built with the `trash-support` feature" "this option is only available if nu is built with the `trash-support` feature"
.into(), .into(),
span, Some(span),
None,
Vec::new(),
)); ));
} }
} }
if targets.is_empty() { if targets.is_empty() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"rm requires target paths".into(), "rm requires target paths".into(),
"needs parameter".into(), "needs parameter".into(),
span, Some(span),
None,
Vec::new(),
)); ));
} }
@ -184,10 +190,12 @@ fn rm(
std::path::MAIN_SEPARATOR std::path::MAIN_SEPARATOR
)) ))
{ {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot remove any parent directory".into(), "Cannot remove any parent directory".into(),
"cannot remove any parent directory".into(), "cannot remove any parent directory".into(),
target.span, Some(target.span),
None,
Vec::new(),
)); ));
} }
@ -214,30 +222,36 @@ fn rm(
all_targets.entry(f.clone()).or_insert_with(|| target.span); all_targets.entry(f.clone()).or_insert_with(|| target.span);
} }
Err(e) => { Err(e) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
format!("Could not remove {:}", path.to_string_lossy()), format!("Could not remove {:}", path.to_string_lossy()),
e.to_string(), e.to_string(),
target.span, Some(target.span),
None,
Vec::new(),
)); ));
} }
} }
} }
} }
Err(e) => { Err(e) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
e.to_string(), e.to_string(),
e.to_string(), e.to_string(),
call.head, Some(call.head),
None,
Vec::new(),
)) ))
} }
}; };
} }
if all_targets.is_empty() && !force { if all_targets.is_empty() && !force {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"No valid paths".into(), "No valid paths".into(),
"no valid paths".into(), "no valid paths".into(),
call.head, Some(call.head),
None,
Vec::new(),
)); ));
} }
@ -301,7 +315,13 @@ fn rm(
if let Err(e) = result { if let Err(e) = result {
let msg = format!("Could not delete because: {:}\nTry '--trash' flag", e); let msg = format!("Could not delete because: {:}\nTry '--trash' flag", e);
Value::Error { Value::Error {
error: ShellError::SpannedLabeledError(msg, e.to_string(), span), error: ShellError::GenericError(
msg,
e.to_string(),
Some(span),
None,
Vec::new(),
),
} }
} else if quiet { } else if quiet {
Value::Nothing { span } Value::Nothing { span }
@ -312,20 +332,24 @@ fn rm(
} else { } else {
let msg = format!("Cannot remove {:}. try --recursive", f.to_string_lossy()); let msg = format!("Cannot remove {:}. try --recursive", f.to_string_lossy());
Value::Error { Value::Error {
error: ShellError::SpannedLabeledError( error: ShellError::GenericError(
msg, msg,
"cannot remove non-empty directory".into(), "cannot remove non-empty directory".into(),
span, Some(span),
None,
Vec::new(),
), ),
} }
} }
} else { } else {
let msg = format!("no such file or directory: {:}", f.to_string_lossy()); let msg = format!("no such file or directory: {:}", f.to_string_lossy());
Value::Error { Value::Error {
error: ShellError::SpannedLabeledError( error: ShellError::GenericError(
msg, msg,
"no such file or directory".into(), "no such file or directory".into(),
span, Some(span),
None,
Vec::new(),
), ),
} }
} }

View File

@ -57,10 +57,12 @@ impl Command for Save {
Err(err) => { Err(err) => {
return Ok(PipelineData::Value( return Ok(PipelineData::Value(
Value::Error { Value::Error {
error: ShellError::SpannedLabeledError( error: ShellError::GenericError(
"Permission denied".into(), "Permission denied".into(),
err.to_string(), err.to_string(),
arg_span, Some(arg_span),
None,
Vec::new(),
), ),
}, },
None, None,

View File

@ -78,10 +78,12 @@ fn first_helper(
match input_peek match input_peek
.peek() .peek()
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Error in first".into(), "Error in first".into(),
"unable to pick on next value".into(), "unable to pick on next value".into(),
call.head, Some(call.head),
None,
Vec::new(),
) )
})? })?
.get_type() .get_type()

View File

@ -96,10 +96,12 @@ pub fn group_by(
let mut group_strategy = Grouper::ByColumn(None); let mut group_strategy = Grouper::ByColumn(None);
if values.is_empty() { if values.is_empty() {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"expected table from pipeline".into(), "expected table from pipeline".into(),
"requires a table input".into(), "requires a table input".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }
@ -133,10 +135,12 @@ pub fn group_by(
let collection: Vec<Value> = s.into_iter().collect(); let collection: Vec<Value> = s.into_iter().collect();
if collection.len() > 1 { if collection.len() > 1 {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"expected one value from the block".into(), "expected one value from the block".into(),
"requires a table with one value for grouping".into(), "requires a table with one value for grouping".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }

View File

@ -131,10 +131,12 @@ fn extract_headers(value: &Value, config: &Config) -> Result<Vec<String>, ShellE
.map(|value| extract_headers(value, config)) .map(|value| extract_headers(value, config))
.next() .next()
.ok_or_else(|| { .ok_or_else(|| {
ShellError::SpannedLabeledError( ShellError::GenericError(
"Found empty list".to_string(), "Found empty list".to_string(),
"unable to extract headers".to_string(), "unable to extract headers".to_string(),
*span, Some(*span),
None,
Vec::new(),
) )
})?, })?,
_ => Err(ShellError::TypeMismatch( _ => Err(ShellError::TypeMismatch(

View File

@ -120,17 +120,21 @@ impl Command for Move {
span: v.span()?, span: v.span()?,
}, },
(Some(_), Some(_)) => { (Some(_), Some(_)) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot move columns".to_string(), "Cannot move columns".to_string(),
"Use either --after, or --before, not both".to_string(), "Use either --after, or --before, not both".to_string(),
call.head, Some(call.head),
None,
Vec::new(),
)) ))
} }
(None, None) => { (None, None) => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot move columns".to_string(), "Cannot move columns".to_string(),
"Missing --after or --before flag".to_string(), "Missing --after or --before flag".to_string(),
call.head, Some(call.head),
None,
Vec::new(),
)) ))
} }
}; };
@ -199,19 +203,23 @@ fn move_record_columns(
match &before_or_after.item { match &before_or_after.item {
BeforeOrAfter::After(after) => { BeforeOrAfter::After(after) => {
if !inp_cols.contains(after) { if !inp_cols.contains(after) {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot move columns".to_string(), "Cannot move columns".to_string(),
"column does not exist".to_string(), "column does not exist".to_string(),
before_or_after.span, Some(before_or_after.span),
None,
Vec::new(),
)); ));
} }
} }
BeforeOrAfter::Before(before) => { BeforeOrAfter::Before(before) => {
if !inp_cols.contains(before) { if !inp_cols.contains(before) {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot move columns".to_string(), "Cannot move columns".to_string(),
"column does not exist".to_string(), "column does not exist".to_string(),
before_or_after.span, Some(before_or_after.span),
None,
Vec::new(),
)); ));
} }
} }
@ -224,10 +232,12 @@ fn move_record_columns(
if let Some(idx) = inp_cols.iter().position(|inp_col| &column_str == inp_col) { if let Some(idx) = inp_cols.iter().position(|inp_col| &column_str == inp_col) {
column_idx.push(idx); column_idx.push(idx);
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Cannot move columns".to_string(), "Cannot move columns".to_string(),
"column does not exist".to_string(), "column does not exist".to_string(),
column.span()?, Some(column.span()?),
None,
Vec::new(),
)); ));
} }
} }

View File

@ -120,10 +120,12 @@ impl Command for Reduce {
} else if let Some(val) = input_iter.next() { } else if let Some(val) = input_iter.next() {
(1, val) (1, val)
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Expected input".to_string(), "Expected input".to_string(),
"needs input".to_string(), "needs input".to_string(),
span, Some(span),
None,
Vec::new(),
)); ));
}; };

View File

@ -73,10 +73,12 @@ fn select(
match members.get(0) { match members.get(0) {
Some(PathMember::Int { val, span }) => { Some(PathMember::Int { val, span }) => {
if members.len() > 1 { if members.len() > 1 {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Select only allows row numbers for rows".into(), "Select only allows row numbers for rows".into(),
"extra after row number".into(), "extra after row number".into(),
*span, Some(*span),
None,
Vec::new(),
)); ));
} }

View File

@ -128,9 +128,12 @@ impl Command for Sort {
pub fn sort(vec: &mut [Value], span: Span, insensitive: bool) -> Result<(), ShellError> { pub fn sort(vec: &mut [Value], span: Span, insensitive: bool) -> Result<(), ShellError> {
if vec.is_empty() { if vec.is_empty() {
return Err(ShellError::LabeledError( return Err(ShellError::GenericError(
"no values to work with".to_string(),
"no values to work with".to_string(), "no values to work with".to_string(),
"".to_string(),
None,
Some("no values to work with".to_string()),
Vec::new(),
)); ));
} }

View File

@ -157,9 +157,12 @@ pub fn sort(
insensitive: bool, insensitive: bool,
) -> Result<(), ShellError> { ) -> Result<(), ShellError> {
if vec.is_empty() { if vec.is_empty() {
return Err(ShellError::LabeledError( return Err(ShellError::GenericError(
"no values to work with".to_string(),
"no values to work with".to_string(), "no values to work with".to_string(),
"".to_string(),
None,
Some("no values to work with".to_string()),
Vec::new(),
)); ));
} }

View File

@ -140,10 +140,12 @@ pub fn split_by(
}); });
Ok(split(&splitter, input, name)?) Ok(split(&splitter, input, name)?)
} }
None => Err(ShellError::SpannedLabeledError( None => Err(ShellError::GenericError(
"expected name".into(), "expected name".into(),
"requires a column name for splitting".into(), "requires a column name for splitting".into(),
name, Some(name),
None,
Vec::new(),
)), )),
} }
} }
@ -225,10 +227,12 @@ pub fn data_split(
} }
} }
_ => { _ => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"unsupported input".into(), "unsupported input".into(),
"requires a table with one row for splitting".into(), "requires a table with one row for splitting".into(),
span, Some(span),
None,
Vec::new(),
)) ))
} }
} }

View File

@ -146,10 +146,12 @@ pub fn transpose(
let mut headers: Vec<String> = vec![]; let mut headers: Vec<String> = vec![];
if !args.rest.is_empty() && args.header_row { if !args.rest.is_empty() && args.header_row {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Can not provide header names and use header row".into(), "Can not provide header names and use header row".into(),
"using header row".into(), "using header row".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }
@ -161,26 +163,32 @@ pub fn transpose(
if let Ok(s) = x.as_string() { if let Ok(s) = x.as_string() {
headers.push(s.to_string()); headers.push(s.to_string());
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Header row needs string headers".into(), "Header row needs string headers".into(),
"used non-string headers".into(), "used non-string headers".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }
} }
_ => { _ => {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Header row is incomplete and can't be used".into(), "Header row is incomplete and can't be used".into(),
"using incomplete header row".into(), "using incomplete header row".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }
} }
} else { } else {
return Err(ShellError::SpannedLabeledError( return Err(ShellError::GenericError(
"Header row is incomplete and can't be used".into(), "Header row is incomplete and can't be used".into(),
"using incomplete header row".into(), "using incomplete header row".into(),
name, Some(name),
None,
Vec::new(),
)); ));
} }
} }

View File

@ -193,7 +193,7 @@ fn from_eml(
.with_body_preview(body_preview) .with_body_preview(body_preview)
.parse() .parse()
.map_err(|_| { .map_err(|_| {
ShellError::CantConvert("structured eml data".into(), "string".into(), head) ShellError::CantConvert("structured eml data".into(), "string".into(), head, None)
})?; })?;
let mut collected = IndexMap::new(); let mut collected = IndexMap::new();

Some files were not shown because too many files have changed in this diff Show More