From d723a4e77e0ac0258f1aba3ce35b8f4644dc7df5 Mon Sep 17 00:00:00 2001 From: Jack Wright Date: Fri, 20 Dec 2024 17:25:25 -0800 Subject: [PATCH] You will now receive an error when trying to use a s3 url with avro or json --- .../src/dataframe/command/core/open.rs | 20 +++++++++++++++++++ .../src/dataframe/values/file_type.rs | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/nu_plugin_polars/src/dataframe/command/core/open.rs b/crates/nu_plugin_polars/src/dataframe/command/core/open.rs index 78061131fb..97a44d8f4f 100644 --- a/crates/nu_plugin_polars/src/dataframe/command/core/open.rs +++ b/crates/nu_plugin_polars/src/dataframe/command/core/open.rs @@ -295,6 +295,10 @@ fn from_avro( ) -> Result { 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> = 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 { 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![], + } +} diff --git a/crates/nu_plugin_polars/src/dataframe/values/file_type.rs b/crates/nu_plugin_polars/src/dataframe/values/file_type.rs index ec032c3bc5..eee30b7be1 100644 --- a/crates/nu_plugin_polars/src/dataframe/values/file_type.rs +++ b/crates/nu_plugin_polars/src/dataframe/values/file_type.rs @@ -24,9 +24,12 @@ impl PolarsFileType { .collect::>() .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![], } }