@@ -27,7 +27,7 @@ use crate::PartitionedFile;
2727use crate :: morsel:: { Morsel , MorselPlan , MorselPlanner , Morselizer } ;
2828use arrow:: array:: { Int32Array , RecordBatch } ;
2929use arrow:: datatypes:: { DataType , Field , Schema } ;
30- use datafusion_common:: { Result , internal_datafusion_err} ;
30+ use datafusion_common:: { DataFusionError , Result , internal_datafusion_err} ;
3131use futures:: Future ;
3232use futures:: future:: BoxFuture ;
3333use futures:: stream:: BoxStream ;
@@ -54,6 +54,18 @@ pub(crate) struct PollsToResolve(pub usize);
5454#[ derive( Debug , Clone , PartialEq , Eq ) ]
5555pub ( crate ) struct MockError ( pub String ) ;
5656
57+ impl Display for MockError {
58+ fn fmt ( & self , f : & mut Formatter ) -> std:: fmt:: Result {
59+ write ! ( f, "{}" , self . 0 )
60+ }
61+ }
62+
63+ impl std:: error:: Error for MockError {
64+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
65+ None
66+ }
67+ }
68+
5769/// Scheduler-visible event captured by the mock morsel test harness.
5870#[ derive( Debug , Clone , PartialEq , Eq ) ]
5971pub ( crate ) enum MorselEvent {
@@ -216,7 +228,7 @@ enum PlannerStep {
216228 result : std:: result:: Result < ( ) , MockError > ,
217229 } ,
218230 Error {
219- message : String ,
231+ error : MockError ,
220232 } ,
221233 None ,
222234}
@@ -289,7 +301,7 @@ impl MockPlannerBuilder {
289301 /// Adds one planning step that fails during CPU planning.
290302 pub ( crate ) fn return_error ( mut self , message : impl Into < String > ) -> Self {
291303 self . steps . push ( PlannerStep :: Error {
292- message : message. into ( ) ,
304+ error : MockError ( message. into ( ) ) ,
293305 } ) ;
294306 self
295307 }
@@ -413,7 +425,9 @@ impl MorselPlanner for MockMorselPlanner {
413425 ) ) as BoxFuture < ' static , Result < ( ) > > ,
414426 ) ) )
415427 }
416- PlannerStep :: Error { message } => Err ( internal_datafusion_err ! ( "{message}" ) ) ,
428+ PlannerStep :: Error { error } => {
429+ Err ( DataFusionError :: External ( Box :: new ( error) ) )
430+ }
417431 PlannerStep :: None => Ok ( None ) ,
418432 }
419433 }
@@ -537,13 +551,13 @@ impl Future for MockIoFuture {
537551 } ) ;
538552 Poll :: Ready ( Ok ( ( ) ) )
539553 }
540- Err ( MockError ( message ) ) => {
554+ Err ( e ) => {
541555 self . observer . push ( MorselEvent :: IoFutureErrored {
542556 planner_name : self . planner_name . clone ( ) ,
543557 io_future_id : self . io_future_id ,
544- message : message . clone ( ) ,
558+ message : e . 0 . clone ( ) ,
545559 } ) ;
546- Poll :: Ready ( Err ( internal_datafusion_err ! ( "{message}" ) ) )
560+ Poll :: Ready ( Err ( DataFusionError :: External ( Box :: new ( e . clone ( ) ) ) ) )
547561 }
548562 }
549563 }
0 commit comments