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

View File

@ -36,7 +36,7 @@ chrono = "0.4.19"
crossterm = "0.23.0"
ctrlc = "3.2.1"
log = "0.4"
miette = "4.1.0"
miette = "4.5.0"
nu-ansi-term = "0.45.1"
nu-cli = { path="./crates/nu-cli", 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" }
crossterm = "0.23.0"
miette = { version = "4.4.0", features = ["fancy"] }
miette = { version = "4.5.0", features = ["fancy"] }
thiserror = "1.0.29"
reedline = { version = "0.4.0", features = ["bashisms"]}

View File

@ -262,7 +262,7 @@ pub fn evaluate_repl(
report_error(
&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);
report_error(
&working_set,
&ShellError::LabeledError(
&ShellError::GenericError(
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);
report_error(
&working_set,
&ShellError::LabeledError(
&ShellError::GenericError(
"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>();
match val {
Ok(f) => Ok(f.abs() >= f64::EPSILON),
Err(_) => Err(ShellError::CantConvertWithHelp(
Err(_) => Err(ShellError::CantConvert(
"boolean".to_string(),
"string".to_string(),
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 },
Err(reason) => {
return Value::Error {
error: ShellError::CantConvertWithHelp(
error: ShellError::CantConvert(
format!("could not parse as datetime using format '{}'", dt.0),
reason.to_string(),
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>() {
Ok(x) => Value::Float { val: x, span: head },
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(),
"string".to_string(),
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> {
match a_string.trim().parse::<bytesize::ByteSize>() {
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) {
Ok(n) => Value::Int { val: n, span: head },
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) {
Ok(n) => n,
Err(_reason) => {
return Err(ShellError::CantConvertWithHelp(
return Err(ShellError::CantConvert(
"int".to_string(),
"string".to_string(),
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)
}
h if h.starts_with("0x") => {
let num = match i64::from_str_radix(h.trim_start_matches("0x"), 16) {
Ok(n) => n,
Err(_reason) => {
return Err(ShellError::CantConvertWithHelp(
let num =
match i64::from_str_radix(h.trim_start_matches("0x"), 16) {
Ok(n) => n,
Err(_reason) => return Err(ShellError::CantConvert(
"int".to_string(),
"string".to_string(),
span,
r#"hexadecimal digits following "0x" should be in 0-9, a-f, or A-F"#
.to_string(),
))
}
};
Some(
r#"hexadecimal digits following "0x" should be in 0-9, a-f, or A-F"#
.to_string(),
),
)),
};
Ok(num)
}
_ => match a_string.parse::<i64>() {
@ -252,6 +253,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
"int".to_string(),
"string".to_string(),
span,
None,
)),
},
},

View File

@ -258,15 +258,20 @@ pub fn action(
),
},
Value::Binary { .. } => Value::Error {
error: ShellError::CantConvertWithHelp(
error: ShellError::CantConvert(
"string".into(),
"binary".into(),
span,
"try using the `decode` command".into(),
Some("try using the `decode` command".into()),
),
},
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)
.map(|err| Value::Error { error: err })
.unwrap_or_else(|| Value::Error {
error: ShellError::SpannedLabeledError(
error: ShellError::GenericError(
"Creating error value not supported.".into(),
"unsupported error format".into(),
span,
Some(span),
None,
Vec::new(),
),
})
.into_pipeline_data())
@ -52,10 +54,12 @@ impl Command for ErrorMake {
make_error(&value)
.map(|err| Value::Error { error: err })
.unwrap_or_else(|| Value::Error {
error: ShellError::SpannedLabeledError(
error: ShellError::GenericError(
"Creating error value not supported.".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 {
val: label_text, ..
}),
) => Some(ShellError::SpannedLabeledError(
) => Some(ShellError::GenericError(
message,
label_text,
Span {
Some(Span {
start: start as usize,
end: end as usize,
},
}),
None,
Vec::new(),
)),
_ => None,
}
}
(Some(Value::String { val: message, .. }), None) => {
Some(ShellError::UnlabeledError(message))
}
(Some(Value::String { val: message, .. }), None) => Some(ShellError::GenericError(
message,
"".to_string(),
None,
None,
Vec::new(),
)),
_ => None,
}
} else {

View File

@ -48,10 +48,12 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
{
pat
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Unexpected import".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(),
x.get_type().to_string(),
result.span()?,
None,
)),
}
}

View File

@ -46,10 +46,12 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
{
pat
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Unexpected import".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 {
// TODO: This is a workaround since call.positional[0].span points at 0 for some reason
// when this error is triggered
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
format!(
"Could not import from '{}'",
String::from_utf8_lossy(&import_pattern.head.name)
),
"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),
"nunique" => Ok(Operation::Nunique),
"quantile" => match quantile {
None => Err(ShellError::SpannedLabeledError(
None => Err(ShellError::GenericError(
"Quantile value not fount".into(),
"Quantile operation requires quantile value".into(),
name.span,
Some(name.span),
None,
Vec::new(),
)),
Some(value) => {
if (value.item < 0.0) | (value.item > 1.0) {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Inappropriate quantile".into(),
"Quantile value should be between 0.0 and 1.0".into(),
value.span,
Some(value.span),
None,
Vec::new(),
))
} else {
Ok(Operation::Quantile(value.item))
@ -82,11 +86,12 @@ impl Operation {
match did_you_mean(&possibilities, selection) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, name.span)),
None => Err(ShellError::SpannedLabeledErrorHelp(
None => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist".into(),
name.span,
"Perhaps you want: mean, sum, min, max, first, last, nunique, quantile, median, var, std, or count".into(),
Some(name.span),
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,
))
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect datatype".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(),
"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,
};
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 {
@ -335,10 +350,12 @@ fn perform_dataframe_aggregation(
Operation::Quantile(quantile) => dataframe
.quantile(quantile, QuantileInterpolOptions::default())
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating quantile".into(),
e.to_string(),
operation_span,
Some(operation_span),
None,
Vec::new(),
)
}),
Operation::Median => Ok(dataframe.median()),
@ -358,11 +375,15 @@ fn perform_dataframe_aggregation(
match did_you_mean(&possibilities, operation.to_str()) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, operation_span)),
None => Err(ShellError::SpannedLabeledErrorHelp(
None => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist".into(),
operation_span,
"Perhaps you want: mean, sum, min, max, quantile, median, var, or std".into(),
Some(operation_span),
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 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)

View File

@ -121,18 +121,22 @@ fn command(
if (&0.0..=&1.0).contains(&val) {
Ok(*val)
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be between 0 and 1".to_string(),
*span,
Some(*span),
None,
Vec::new(),
))
}
}
_ => match value.span() {
Ok(span) => Err(ShellError::SpannedLabeledError(
Ok(span) => Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be a float".to_string(),
span,
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(e),
},
@ -242,7 +246,13 @@ fn command(
DataFrame::new(res)
.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))
}

View File

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

View File

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

View File

@ -112,7 +112,13 @@ fn command(
df.as_ref()
.drop_nulls(subset_slice)
.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))
}

View File

@ -115,11 +115,12 @@ fn command(
df.as_ref()
.to_dummies()
.map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating dummies".into(),
e.to_string(),
call.head,
"The only allowed column types for dummies are String or Int".into(),
Some(call.head),
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))

View File

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

View File

@ -67,10 +67,12 @@ fn command(
df.as_ref()
.select(&col_string)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.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
// in a NuGroupBy
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();

View File

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

View File

@ -148,29 +148,35 @@ fn command(
.as_ref()
.melt(&id_col_string, &val_col_string)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating melt".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
if let Some(name) = &variable_name {
res.rename("variable", &name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error renaming column".into(),
e.to_string(),
name.span,
Some(name.span),
None,
Vec::new(),
)
})?;
}
if let Some(name) = &value_name {
res.rename("value", &name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error renaming column".into(),
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,
) -> Result<(), ShellError> {
if cols.is_empty() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Merge error".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 {
for w in cols.windows(2) {
let l_series = df.column(w[0].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})?;
let r_series = df.column(w[1].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})?;
if l_series.dtype() != r_series.dtype() {
return Err(ShellError::SpannedLabeledErrorHelp(
return Err(ShellError::GenericError(
"Merge error".into(),
"found different column types in list".into(),
col_span,
format!(
Some(col_span),
Some(format!(
"datatypes {} and {} are incompatible",
l_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 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);
@ -125,10 +131,12 @@ fn from_parquet(
};
reader.finish().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Parquet reader error".into(),
format!("{:?}", e),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
}
@ -140,14 +148,26 @@ fn from_json(
) -> Result<polars::prelude::DataFrame, ShellError> {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
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 reader = JsonReader::new(buf_reader);
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)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating CSV reader".into(),
e.to_string(),
file.span,
Some(file.span),
None,
Vec::new(),
)
})?
.with_encoding(CsvEncoding::LossyUtf8);
@ -177,10 +199,12 @@ fn from_csv(
None => csv_reader,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one character".into(),
d.span,
Some(d.span),
None,
Vec::new(),
));
} else {
let delimiter = match d.item.chars().next() {
@ -210,10 +234,12 @@ fn from_csv(
};
csv_reader.finish().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Parquet reader error".into(),
format!("{:?}", e),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
}

View File

@ -28,11 +28,12 @@ impl Operation {
"max" => Ok(Operation::Max),
"mean" => Ok(Operation::Mean),
"median" => Ok(Operation::Median),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist for pivot".into(),
name.span,
"Options: first, sum, min, max, mean, median".into(),
Some(name.span),
Some("Options: first, sum, min, max, mean, median".into()),
Vec::new(),
)),
}
}
@ -116,7 +117,13 @@ fn command(
Operation::Median => pivot.median(),
}
.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))
}
@ -126,7 +133,13 @@ fn check_pivot_column(
col: &Spanned<String>,
) -> Result<(), ShellError> {
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() {
@ -139,10 +152,12 @@ fn check_pivot_column(
| DataType::Int32
| DataType::Int64
| DataType::Utf8 => Ok(()),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()),
col.span,
Some(col.span),
None,
Vec::new(),
)),
}
}
@ -152,7 +167,13 @@ fn check_value_column(
col: &Spanned<String>,
) -> Result<(), ShellError> {
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() {
@ -166,10 +187,12 @@ fn check_value_column(
| DataType::Int64
| DataType::Float32
| DataType::Float64 => Ok(()),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()),
col.span,
Some(col.span),
None,
Vec::new(),
)),
}
}

View File

@ -72,7 +72,13 @@ fn command(
df.as_mut()
.rename(&from, &to)
.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| {
PipelineData::Value(

View File

@ -77,29 +77,36 @@ fn command(
match (rows, fraction) {
(Some(rows), None) => df.as_ref().sample_n(rows.item, replace, 0).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating sample".into(),
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| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
frac.span,
Some(frac.span),
None,
Vec::new(),
)
}),
(Some(_), Some(_)) => Err(ShellError::SpannedLabeledError(
(Some(_), Some(_)) => Err(ShellError::GenericError(
"Incompatible flags".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 criterion was found".into(),
call.head,
"Perhaps you want to use the flag -n or -f".into(),
Some(call.head),
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))

View File

@ -95,10 +95,12 @@ fn command(
df.as_ref()
.sort(columns, reverse)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error sorting dataframe".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
@ -111,20 +113,24 @@ fn command(
df.as_ref()
.sort(&col_string, reverse)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error sorting dataframe".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.map(|df| {
PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)
})
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Missing columns".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() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
index.cast(&DataType::UInt32).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
index_span,
Some(index_span),
None,
Vec::new(),
)
})
}
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"Series with incorrect type".into(),
call.head,
"Consider using a Series with type int type".into(),
Some(call.head),
Some("Consider using a Series with type int type".into()),
Vec::new(),
)),
}?;
let indices = casted.u32().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
index_span,
Some(index_span),
None,
Vec::new(),
)
})?;
@ -122,10 +127,12 @@ fn command(
df.as_ref()
.take(indices)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error taking values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
.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 file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
file_name.span,
Some(file_name.span),
None,
Vec::new(),
)
})?;
@ -93,10 +95,12 @@ fn command(
None => writer,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one char".into(),
d.span,
Some(d.span),
None,
Vec::new(),
));
} else {
let delimiter = match d.item.chars().next() {
@ -110,10 +114,12 @@ fn command(
};
writer.finish(df.as_mut()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error writing to file".into(),
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 file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
file_name.span,
Some(file_name.span),
None,
Vec::new(),
)
})?;
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 {

View File

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

View File

@ -74,10 +74,12 @@ fn command(
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to 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 bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to 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),
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
span,
"Allowed values: max, min, sum".into(),
Some(span),
Some("Allowed values: max, min, sum".into()),
Vec::new(),
)),
}
}
@ -102,10 +103,12 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Found object series".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 series = df.as_series(call.head)?;
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 {
@ -76,10 +82,12 @@ fn command(
let mut res = res
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating datetime".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

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

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
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 bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to 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)?
.arg_unique()
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error extracting unique values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

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

View File

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

View File

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

View File

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

View File

@ -65,7 +65,13 @@ fn command(
let series = df.as_series(call.head)?;
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();

View File

@ -82,16 +82,20 @@ fn command(
let bool_mask = match mask.dtype() {
DataType::Boolean => mask.bool().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to bool".into(),
e.to_string(),
mask_span,
Some(mask_span),
None,
Vec::new(),
)
}),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".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 {
Value::Int { val, span } => {
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| {
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)
}
Value::Float { val, span } => {
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| {
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)
}
Value::String { val, span } => {
let chunked = series.as_ref().utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
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();
@ -139,13 +175,15 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect value type".into(),
format!(
"this value cannot be set in a series of type '{}'",
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 res = df.as_series(call.head)?.n_unique().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error counting unique values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -22,11 +22,12 @@ impl RollType {
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
"mean" => Ok(Self::Mean),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
span,
"Allowed values: min, max, sum, mean".into(),
Some(span),
Some("Allowed values: min, max, sum, mean".into()),
Vec::new(),
)),
}
}
@ -123,10 +124,12 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Found object series".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| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating rolling values".into(),
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_chunked = other_series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The concatenate only with string columns".into(),
e.to_string(),
other_span,
Some(other_span),
None,
Vec::new(),
)
})?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The concatenate only with string columns".into(),
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 chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The contains command only with string columns".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let res = chunked.contains(&pattern).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error searching in series".into(),
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 series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error convertion to string".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res = chunked.replace(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding pattern other".into(),
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 series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error convertion to string".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res = chunked.replace_all(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding pattern other".into(),
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 chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-lengths command can only be used with string columns".into(),
Some(call.head),
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 chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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| {
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());

View File

@ -69,11 +69,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to date".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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 casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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 casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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 res = series.unique().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating unique values".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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 res = series.value_counts().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating value counts values".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
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);
NuDataFrame::series_to_value(res, operation_span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Division error".into(),
e.to_string(),
right.span()?,
Some(right.span()?),
None,
Vec::new(),
)),
}
}
@ -121,10 +123,12 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incompatible types".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);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incompatible types".into(),
"unable to cast to boolean".into(),
right.span()?,
Some(right.span()?),
None,
Vec::new(),
)),
}
}
@ -413,10 +419,12 @@ where
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -424,13 +432,15 @@ where
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -450,10 +460,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -476,10 +488,12 @@ where
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -487,13 +501,15 @@ where
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with a decimal value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -513,10 +529,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -537,10 +555,12 @@ where
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -556,10 +576,12 @@ where
.expect("already checked for casting");
compare_casted_i64(Ok(&casted), val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -567,13 +589,15 @@ where
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -593,10 +617,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -619,10 +645,12 @@ where
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -630,13 +658,15 @@ where
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with a decimal value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -656,10 +686,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
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();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Error using contains".into(),
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(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}

View File

@ -122,7 +122,13 @@ pub fn create_column(
}
DataType::UInt8 => {
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
.into_iter()
@ -141,7 +147,13 @@ pub fn create_column(
}
DataType::UInt16 => {
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
.into_iter()
@ -160,7 +172,13 @@ pub fn create_column(
}
DataType::UInt32 => {
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
.into_iter()
@ -179,7 +197,13 @@ pub fn create_column(
}
DataType::UInt64 => {
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
.into_iter()
@ -198,7 +222,13 @@ pub fn create_column(
}
DataType::Int8 => {
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
.into_iter()
@ -217,7 +247,13 @@ pub fn create_column(
}
DataType::Int16 => {
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
.into_iter()
@ -236,7 +272,13 @@ pub fn create_column(
}
DataType::Int32 => {
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
.into_iter()
@ -255,7 +297,13 @@ pub fn create_column(
}
DataType::Int64 => {
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
.into_iter()
@ -274,7 +322,13 @@ pub fn create_column(
}
DataType::Float32 => {
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
.into_iter()
@ -293,7 +347,13 @@ pub fn create_column(
}
DataType::Float64 => {
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
.into_iter()
@ -309,7 +369,13 @@ pub fn create_column(
}
DataType::Boolean => {
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
@ -326,7 +392,13 @@ pub fn create_column(
}
DataType::Utf8 => {
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
@ -350,9 +422,12 @@ pub fn create_column(
.downcast_ref::<ChunkedArray<ObjectType<DataFrameValue>>>();
match casted {
None => Err(ShellError::LabeledError(
None => Err(ShellError::GenericError(
"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) => {
let values = ca
@ -371,7 +446,13 @@ pub fn create_column(
}
DataType::Date => {
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
@ -401,7 +482,13 @@ pub fn create_column(
}
DataType::Datetime(_, _) => {
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
@ -431,7 +518,13 @@ pub fn create_column(
}
DataType::Time => {
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
@ -449,9 +542,12 @@ pub fn create_column(
Ok(Column::new(casted.name().into(), values))
}
e => Err(ShellError::LabeledError(
e => Err(ShellError::GenericError(
"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)
.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> {
match DataFrame::new(vec![series]) {
Ok(dataframe) => Ok(NuDataFrame::dataframe_into_value(dataframe, span)),
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Error creating dataframe".into(),
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> {
let dataframe = DataFrame::new(columns).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating dataframe".into(),
format!("Unable to create DataFrame: {}", e),
span,
Some(span),
None,
Vec::new(),
)
})?;
@ -183,12 +187,14 @@ impl NuDataFrame {
"dataframe".into(),
"non-dataframe".into(),
span,
None,
)),
},
x => Err(ShellError::CantConvert(
"dataframe".into(),
x.get_type().to_string(),
x.span()?,
None,
)),
}
}
@ -212,7 +218,13 @@ impl NuDataFrame {
})?;
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))
@ -224,10 +236,12 @@ impl NuDataFrame {
pub fn as_series(&self, span: Span) -> Result<Series, ShellError> {
if !self.is_series() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Error using as series".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>>();
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
@ -183,10 +185,12 @@ impl NuDataFrame {
match res {
Ok(s) => Ok(s.clone()),
Err(e) => Err({
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append: {}", e),
span,
Some(span),
None,
Vec::new(),
)
}),
}
@ -194,10 +198,12 @@ impl NuDataFrame {
.collect::<Result<Vec<Series>, ShellError>>()?;
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append dataframes: {}", e),
span,
Some(span),
None,
Vec::new(),
)
})?;

View File

@ -78,12 +78,14 @@ impl NuGroupBy {
"groupby".into(),
"non-dataframe".into(),
span,
None,
)),
},
x => Err(ShellError::CantConvert(
"groupby".into(),
x.get_type().to_string(),
x.span()?,
None,
)),
}
}
@ -95,7 +97,13 @@ impl NuGroupBy {
pub fn to_groupby(&self) -> Result<GroupBy, ShellError> {
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(

View File

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

View File

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

View File

@ -57,17 +57,21 @@ impl Command for ViewSource {
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data())
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Cannot view value".to_string(),
"the command does not have a viewable block".to_string(),
arg_span,
Some(arg_span),
None,
Vec::new(),
))
}
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Cannot view value".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()) {
@ -78,24 +82,30 @@ impl Command for ViewSource {
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data())
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Cannot view value".to_string(),
"the module does not have a viewable block".to_string(),
arg_span,
Some(arg_span),
None,
Vec::new(),
))
}
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Cannot view 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(),
"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) {
Ok(p) => p,
Err(e) => {
return Err(ShellError::DirectoryNotFoundHelp(
return Err(ShellError::DirectoryNotFound(
*span,
format!("IO Error: {:?}", e),
Some(format!("IO Error: {:?}", e)),
))
}
};
@ -69,9 +69,9 @@ impl Command for Cd {
}
Err(e) => {
return Err(ShellError::DirectoryNotFoundHelp(
return Err(ShellError::DirectoryNotFound(
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) {
Ok(files) => files.collect(),
Err(e) => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
e.to_string(),
"invalid pattern".to_string(),
src.span,
Some(src.span),
None,
Vec::new(),
))
}
};
if sources.is_empty() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"No matches found".into(),
"no matches found".into(),
src.span,
Some(src.span),
None,
Vec::new(),
));
}
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(),
"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()));
if any_source_is_dir && !recursive {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Directories must be copied using \"--recursive\"".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 {
if src.is_file() {
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() {
Some(name) => destination.join(name),
None => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Copy aborted. 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| {
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)| {
@ -161,13 +183,25 @@ impl Command for Cp {
for (s, d) in sources {
if s.is_dir() && !d.exists() {
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() {
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) {
Ok(p) => p,
Err(e) => {
return Err(ShellError::LabeledError(
return Err(ShellError::GenericError(
"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))]
let error_msg = String::from("Permission denied");
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Permission denied".to_string(),
error_msg,
p_tag,
Some(p_tag),
None,
Vec::new(),
));
}
if is_empty_dir(&expanded) {
@ -129,9 +131,12 @@ impl Command for Ls {
let mut paths_peek = paths.peekable();
if paths_peek.peek().is_none() {
return Err(ShellError::LabeledError(
return Err(ShellError::GenericError(
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())
}
.ok_or_else(|| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
format!("Invalid file name: {:}", path.to_string_lossy()),
"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);
if sources.is_empty() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"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)
|| (!destination.exists() && sources.len() > 1)
{
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Can only move multiple sources if destination is a directory".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)));
if destination.exists() && destination.is_dir() && sources.len() == 1 {
if let Some(Ok(filename)) = some_if_source_is_destination {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
format!(
"Not possible to move {:?} to itself",
filename.file_name().expect("Invalid file name")
),
"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 {
return Err(ShellError::DirectoryNotFound(to_span));
return Err(ShellError::DirectoryNotFound(to_span, None));
}
let mut to = to;
if to.is_dir() {
let from_file_name = match from.file_name() {
Some(name) => name,
None => return Err(ShellError::DirectoryNotFound(to_span)),
None => return Err(ShellError::DirectoryNotFound(to_span, None)),
};
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)
} {
Ok(_) => Ok(()),
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
format!("Could not move {:?} to {:?}. {:}", from, to, e),
"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))]
let error_msg = String::from("Permission denied");
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Permission denied".into(),
error_msg,
arg_span,
Some(arg_span),
None,
Vec::new(),
))
} else {
let mut file = match std::fs::File::open(path) {
Ok(file) => file,
Err(err) => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Permission denied".into(),
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) {
Ok(conn) => match read_sqlite_db(conn, call_span) {
Ok(data) => Ok(data),
Err(err) => Err(ShellError::SpannedLabeledError(
Err(err) => Err(ShellError::GenericError(
"Failed to read from SQLite database".into(),
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(),
err.to_string(),
call_span,
Some(call_span),
None,
Vec::new(),
)),
}
}

View File

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

View File

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

View File

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

View File

@ -96,10 +96,12 @@ pub fn group_by(
let mut group_strategy = Grouper::ByColumn(None);
if values.is_empty() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"expected table from pipeline".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();
if collection.len() > 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"expected one value from the block".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))
.next()
.ok_or_else(|| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Found empty list".to_string(),
"unable to extract headers".to_string(),
*span,
Some(*span),
None,
Vec::new(),
)
})?,
_ => Err(ShellError::TypeMismatch(

View File

@ -120,17 +120,21 @@ impl Command for Move {
span: v.span()?,
},
(Some(_), Some(_)) => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Cannot move columns".to_string(),
"Use either --after, or --before, not both".to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
))
}
(None, None) => {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Cannot move columns".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 {
BeforeOrAfter::After(after) => {
if !inp_cols.contains(after) {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Cannot move columns".to_string(),
"column does not exist".to_string(),
before_or_after.span,
Some(before_or_after.span),
None,
Vec::new(),
));
}
}
BeforeOrAfter::Before(before) => {
if !inp_cols.contains(before) {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Cannot move columns".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) {
column_idx.push(idx);
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Cannot move columns".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() {
(1, val)
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Expected 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) {
Some(PathMember::Int { val, span }) => {
if members.len() > 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Select only allows row numbers for rows".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> {
if vec.is_empty() {
return Err(ShellError::LabeledError(
"no values to work with".to_string(),
return Err(ShellError::GenericError(
"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,
) -> Result<(), ShellError> {
if vec.is_empty() {
return Err(ShellError::LabeledError(
"no values to work with".to_string(),
return Err(ShellError::GenericError(
"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)?)
}
None => Err(ShellError::SpannedLabeledError(
None => Err(ShellError::GenericError(
"expected name".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(),
"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![];
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(),
"using header row".into(),
name,
Some(name),
None,
Vec::new(),
));
}
@ -161,26 +163,32 @@ pub fn transpose(
if let Ok(s) = x.as_string() {
headers.push(s.to_string());
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Header row needs 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(),
"using incomplete header row".into(),
name,
Some(name),
None,
Vec::new(),
));
}
}
} else {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Header row is incomplete and can't be used".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)
.parse()
.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();

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