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
141 changed files with 1569 additions and 689 deletions

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| {