Skip to content

Commit

Permalink
fix: do NOT convert errors to strings (#4436)
Browse files Browse the repository at this point in the history
Wrap them into proper containers instead.

Fixes #4434.
  • Loading branch information
crepererum authored Dec 1, 2022
1 parent d9e58db commit ffe97e5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
12 changes: 3 additions & 9 deletions datafusion-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,16 @@ impl Command {
) -> Result<()> {
let now = Instant::now();
match self {
Self::Help => print_options
.print_batches(&[all_commands_info()], now)
.map_err(|e| DataFusionError::Execution(e.to_string())),
Self::Help => print_options.print_batches(&[all_commands_info()], now),
Self::ListTables => {
let df = ctx.sql("SHOW TABLES").await?;
let batches = df.collect().await?;
print_options
.print_batches(&batches, now)
.map_err(|e| DataFusionError::Execution(e.to_string()))
print_options.print_batches(&batches, now)
}
Self::DescribeTable(name) => {
let df = ctx.sql(&format!("SHOW COLUMNS FROM {}", name)).await?;
let batches = df.collect().await?;
print_options
.print_batches(&batches, now)
.map_err(|e| DataFusionError::Execution(e.to_string()))
print_options.print_batches(&batches, now)
}
Self::Include(filename) => {
if let Some(filename) = filename {
Expand Down
4 changes: 2 additions & 2 deletions datafusion-cli/src/object_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn build_s3_object_store(url: &Url) -> Result<Arc<dyn object_store::ObjectStore>
let host = get_host_name(url)?;
match AmazonS3Builder::from_env().with_bucket_name(host).build() {
Ok(s3) => Ok(Arc::new(s3)),
Err(err) => Err(DataFusionError::Execution(err.to_string())),
Err(err) => Err(DataFusionError::External(Box::new(err))),
}
}

Expand All @@ -73,7 +73,7 @@ fn build_gcs_object_store(url: &Url) -> Result<Arc<dyn object_store::ObjectStore
}
match builder.build() {
Ok(gcs) => Ok(Arc::new(gcs)),
Err(err) => Err(DataFusionError::Execution(err.to_string())),
Err(err) => Err(DataFusionError::External(Box::new(err))),
}
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion-cli/src/print_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ macro_rules! batches_to_json {
writer.write_batches($batches)?;
writer.finish()?;
}
String::from_utf8(bytes).map_err(|e| DataFusionError::Execution(e.to_string()))?
String::from_utf8(bytes).map_err(|e| DataFusionError::External(Box::new(e)))?
}};
}

Expand All @@ -64,8 +64,8 @@ fn print_batches_with_sep(batches: &[RecordBatch], delimiter: u8) -> Result<Stri
writer.write(batch)?;
}
}
let formatted = String::from_utf8(bytes)
.map_err(|e| DataFusionError::Execution(e.to_string()))?;
let formatted =
String::from_utf8(bytes).map_err(|e| DataFusionError::External(Box::new(e)))?;
Ok(formatted)
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/datasource/listing_table_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ impl TableProviderFactory for ListingTableFactory {
.table_partition_cols
.iter()
.map(|col| {
schema.field_with_name(col).map_err(|arrow_err| {
DataFusionError::Execution(arrow_err.to_string())
})
schema
.field_with_name(col)
.map_err(DataFusionError::ArrowError)
})
.collect::<datafusion_common::Result<Vec<_>>>()?
.into_iter()
Expand Down
17 changes: 12 additions & 5 deletions datafusion/core/src/physical_plan/repartition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::physical_plan::{
};
use arrow::array::{ArrayRef, UInt64Builder};
use arrow::datatypes::SchemaRef;
use arrow::error::Result as ArrowResult;
use arrow::error::{ArrowError, Result as ArrowResult};
use arrow::record_batch::RecordBatch;
use log::debug;
use tokio_stream::wrappers::UnboundedReceiverStream;
Expand Down Expand Up @@ -482,18 +482,25 @@ impl RepartitionExec {
match input_task.await {
// Error in joining task
Err(e) => {
let e = Arc::new(e);

for (_, tx) in txs {
let err = DataFusionError::Execution(format!("Join Error: {}", e));
let err = Err(err.into());
let err = Err(ArrowError::ExternalError(Box::new(
DataFusionError::Context(
"Join Error".to_string(),
Box::new(DataFusionError::External(Box::new(Arc::clone(&e)))),
),
)));
tx.send(Some(err)).ok();
}
}
// Error from running input task
Ok(Err(e)) => {
let e = Arc::new(e);

for (_, tx) in txs {
// wrap it because need to send error to all output partitions
let err = DataFusionError::Execution(e.to_string());
let err = Err(err.into());
let err = Err(ArrowError::ExternalError(Box::new(e.clone())));
tx.send(Some(err)).ok();
}
}
Expand Down
10 changes: 5 additions & 5 deletions datafusion/physical-expr/src/regex_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn regexp_replace<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef>
patterns.insert(pattern.to_string(), re.clone());
Ok(re)
},
Err(err) => Err(DataFusionError::Execution(err.to_string())),
Err(err) => Err(DataFusionError::External(Box::new(err))),
}
}
};
Expand Down Expand Up @@ -182,7 +182,7 @@ pub fn regexp_replace<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef>
patterns.insert(pattern, re.clone());
Ok(re)
},
Err(err) => Err(DataFusionError::Execution(err.to_string())),
Err(err) => Err(DataFusionError::External(Box::new(err))),
}
}
};
Expand Down Expand Up @@ -254,8 +254,8 @@ fn _regexp_replace_static_pattern_replace<T: OffsetSizeTrait>(
None => (pattern.to_string(), 1),
};

let re = Regex::new(&pattern)
.map_err(|err| DataFusionError::Execution(err.to_string()))?;
let re =
Regex::new(&pattern).map_err(|err| DataFusionError::External(Box::new(err)))?;

// Replaces the posix groups in the replacement string
// with rust ones.
Expand Down Expand Up @@ -522,7 +522,7 @@ mod tests {
let pattern_err = re.expect_err("broken pattern should have failed");
assert_eq!(
pattern_err.to_string(),
"Execution error: regex parse error:\n [\n ^\nerror: unclosed character class"
"External error: regex parse error:\n [\n ^\nerror: unclosed character class"
);
}

Expand Down

0 comments on commit ffe97e5

Please sign in to comment.