You will now receive an error when trying to use a s3 url with avro or json

This commit is contained in:
Jack Wright 2024-12-20 17:25:25 -08:00
parent 13bc9508d0
commit d723a4e77e
2 changed files with 26 additions and 3 deletions

View File

@ -295,6 +295,10 @@ fn from_avro(
) -> Result<Value, ShellError> {
let file_path = resource.path;
let file_span = resource.span;
if resource.cloud_options.is_some() {
return Err(cloud_not_supported(PolarsFileType::Avro, file_span));
}
let columns: Option<Vec<String>> = call.get_flag("columns")?;
let r = File::open(file_path).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
@ -396,6 +400,9 @@ fn from_json(
) -> Result<Value, ShellError> {
let file_path = resource.path;
let file_span = resource.span;
if resource.cloud_options.is_some() {
return Err(cloud_not_supported(PolarsFileType::Json, file_span));
}
let file = File::open(file_path).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
@ -631,3 +638,16 @@ fn from_csv(
df.cache_and_to_value(plugin, engine, call.head)
}
}
fn cloud_not_supported(file_type: PolarsFileType, span: Span) -> ShellError {
ShellError::GenericError {
error: format!(
"Cloud operations not supported for file type {}",
file_type.to_str()
),
msg: "".into(),
span: Some(span),
help: None,
inner: vec![],
}
}

View File

@ -24,9 +24,12 @@ impl PolarsFileType {
.collect::<Vec<&'static str>>()
.join(", ");
ShellError::FileNotFoundCustom {
msg: format!("Unsupported type {extension} expected {type_string}"),
span,
ShellError::GenericError {
error: format!("Unsupported type {extension} expected {type_string}"),
msg: "".into(),
span: Some(span),
help: None,
inner: vec![],
}
}