@@ -138,12 +138,12 @@ fn create_array(reader: &mut ArrayReader, field: &Field) -> Result<ArrayRef, Arr
138
138
let index_buffers = [ reader. next_buffer ( ) ?, reader. next_buffer ( ) ?] ;
139
139
140
140
let dict_id = field. dict_id ( ) . ok_or_else ( || {
141
- ArrowError :: IoError ( format ! ( "Field {field} does not have dict id" ) )
141
+ ArrowError :: ParseError ( format ! ( "Field {field} does not have dict id" ) )
142
142
} ) ?;
143
143
144
144
let value_array =
145
145
reader. dictionaries_by_id . get ( & dict_id) . ok_or_else ( || {
146
- ArrowError :: IoError ( format ! (
146
+ ArrowError :: ParseError ( format ! (
147
147
"Cannot find a dictionary batch with dict id: {dict_id}"
148
148
) )
149
149
} ) ?;
@@ -193,7 +193,7 @@ fn create_array(reader: &mut ArrayReader, field: &Field) -> Result<ArrayRef, Arr
193
193
let null_count = node. null_count ( ) ;
194
194
195
195
if length != null_count {
196
- return Err ( ArrowError :: IoError ( format ! (
196
+ return Err ( ArrowError :: SchemaError ( format ! (
197
197
"Field {field} of NullArray has unequal null_count {null_count} and len {length}"
198
198
) ) ) ;
199
199
}
@@ -325,7 +325,7 @@ impl<'a> ArrayReader<'a> {
325
325
326
326
fn next_node ( & mut self , field : & Field ) -> Result < & ' a FieldNode , ArrowError > {
327
327
self . nodes . next ( ) . ok_or_else ( || {
328
- ArrowError :: IoError ( format ! (
328
+ ArrowError :: SchemaError ( format ! (
329
329
"Invalid data for schema. {} refers to node not found in schema" ,
330
330
field
331
331
) )
@@ -402,10 +402,10 @@ pub fn read_record_batch(
402
402
metadata : & MetadataVersion ,
403
403
) -> Result < RecordBatch , ArrowError > {
404
404
let buffers = batch. buffers ( ) . ok_or_else ( || {
405
- ArrowError :: IoError ( "Unable to get buffers from IPC RecordBatch" . to_string ( ) )
405
+ ArrowError :: IpcError ( "Unable to get buffers from IPC RecordBatch" . to_string ( ) )
406
406
} ) ?;
407
407
let field_nodes = batch. nodes ( ) . ok_or_else ( || {
408
- ArrowError :: IoError ( "Unable to get field nodes from IPC RecordBatch" . to_string ( ) )
408
+ ArrowError :: IpcError ( "Unable to get field nodes from IPC RecordBatch" . to_string ( ) )
409
409
} ) ?;
410
410
let batch_compression = batch. compression ( ) ;
411
411
let compression = batch_compression
@@ -462,7 +462,7 @@ pub fn read_dictionary(
462
462
metadata : & crate :: MetadataVersion ,
463
463
) -> Result < ( ) , ArrowError > {
464
464
if batch. isDelta ( ) {
465
- return Err ( ArrowError :: IoError (
465
+ return Err ( ArrowError :: InvalidArgumentError (
466
466
"delta dictionary batches not supported" . to_string ( ) ,
467
467
) ) ;
468
468
}
@@ -569,14 +569,14 @@ impl<R: Read + Seek> FileReader<R> {
569
569
let mut magic_buffer: [ u8 ; 6 ] = [ 0 ; 6 ] ;
570
570
reader. read_exact ( & mut magic_buffer) ?;
571
571
if magic_buffer != super :: ARROW_MAGIC {
572
- return Err ( ArrowError :: IoError (
572
+ return Err ( ArrowError :: ParseError (
573
573
"Arrow file does not contain correct header" . to_string ( ) ,
574
574
) ) ;
575
575
}
576
576
reader. seek ( SeekFrom :: End ( -6 ) ) ?;
577
577
reader. read_exact ( & mut magic_buffer) ?;
578
578
if magic_buffer != super :: ARROW_MAGIC {
579
- return Err ( ArrowError :: IoError (
579
+ return Err ( ArrowError :: ParseError (
580
580
"Arrow file does not contain correct footer" . to_string ( ) ,
581
581
) ) ;
582
582
}
@@ -592,11 +592,11 @@ impl<R: Read + Seek> FileReader<R> {
592
592
reader. read_exact ( & mut footer_data) ?;
593
593
594
594
let footer = crate :: root_as_footer ( & footer_data[ ..] ) . map_err ( |err| {
595
- ArrowError :: IoError ( format ! ( "Unable to get root as footer: {err:?}" ) )
595
+ ArrowError :: ParseError ( format ! ( "Unable to get root as footer: {err:?}" ) )
596
596
} ) ?;
597
597
598
598
let blocks = footer. recordBatches ( ) . ok_or_else ( || {
599
- ArrowError :: IoError (
599
+ ArrowError :: ParseError (
600
600
"Unable to get record batches from IPC Footer" . to_string ( ) ,
601
601
)
602
602
} ) ?;
@@ -633,7 +633,9 @@ impl<R: Read + Seek> FileReader<R> {
633
633
reader. read_exact ( & mut block_data) ?;
634
634
635
635
let message = crate :: root_as_message ( & block_data[ ..] ) . map_err ( |err| {
636
- ArrowError :: IoError ( format ! ( "Unable to get root as message: {err:?}" ) )
636
+ ArrowError :: ParseError ( format ! (
637
+ "Unable to get root as message: {err:?}"
638
+ ) )
637
639
} ) ?;
638
640
639
641
match message. header_type ( ) {
@@ -657,7 +659,7 @@ impl<R: Read + Seek> FileReader<R> {
657
659
) ?;
658
660
}
659
661
t => {
660
- return Err ( ArrowError :: IoError ( format ! (
662
+ return Err ( ArrowError :: ParseError ( format ! (
661
663
"Expecting DictionaryBatch in dictionary blocks, found {t:?}."
662
664
) ) ) ;
663
665
}
@@ -705,7 +707,7 @@ impl<R: Read + Seek> FileReader<R> {
705
707
/// Sets the current block to the index, allowing random reads
706
708
pub fn set_index ( & mut self , index : usize ) -> Result < ( ) , ArrowError > {
707
709
if index >= self . total_blocks {
708
- Err ( ArrowError :: IoError ( format ! (
710
+ Err ( ArrowError :: InvalidArgumentError ( format ! (
709
711
"Cannot set batch to index {} from {} total batches" ,
710
712
index, self . total_blocks
711
713
) ) )
@@ -732,25 +734,25 @@ impl<R: Read + Seek> FileReader<R> {
732
734
let mut block_data = vec ! [ 0 ; meta_len as usize ] ;
733
735
self . reader . read_exact ( & mut block_data) ?;
734
736
let message = crate :: root_as_message ( & block_data[ ..] ) . map_err ( |err| {
735
- ArrowError :: IoError ( format ! ( "Unable to get root as footer: {err:?}" ) )
737
+ ArrowError :: ParseError ( format ! ( "Unable to get root as footer: {err:?}" ) )
736
738
} ) ?;
737
739
738
740
// some old test data's footer metadata is not set, so we account for that
739
741
if self . metadata_version != crate :: MetadataVersion :: V1
740
742
&& message. version ( ) != self . metadata_version
741
743
{
742
- return Err ( ArrowError :: IoError (
744
+ return Err ( ArrowError :: IpcError (
743
745
"Could not read IPC message as metadata versions mismatch" . to_string ( ) ,
744
746
) ) ;
745
747
}
746
748
747
749
match message. header_type ( ) {
748
- crate :: MessageHeader :: Schema => Err ( ArrowError :: IoError (
750
+ crate :: MessageHeader :: Schema => Err ( ArrowError :: IpcError (
749
751
"Not expecting a schema when messages are read" . to_string ( ) ,
750
752
) ) ,
751
753
crate :: MessageHeader :: RecordBatch => {
752
754
let batch = message. header_as_record_batch ( ) . ok_or_else ( || {
753
- ArrowError :: IoError (
755
+ ArrowError :: IpcError (
754
756
"Unable to read IPC message as record batch" . to_string ( ) ,
755
757
)
756
758
} ) ?;
@@ -774,7 +776,7 @@ impl<R: Read + Seek> FileReader<R> {
774
776
crate :: MessageHeader :: NONE => {
775
777
Ok ( None )
776
778
}
777
- t => Err ( ArrowError :: IoError ( format ! (
779
+ t => Err ( ArrowError :: InvalidArgumentError ( format ! (
778
780
"Reading types other than record batches not yet supported, unable to read {t:?}"
779
781
) ) ) ,
780
782
}
@@ -886,11 +888,11 @@ impl<R: Read> StreamReader<R> {
886
888
reader. read_exact ( & mut meta_buffer) ?;
887
889
888
890
let message = crate :: root_as_message ( meta_buffer. as_slice ( ) ) . map_err ( |err| {
889
- ArrowError :: IoError ( format ! ( "Unable to get root as message: {err:?}" ) )
891
+ ArrowError :: ParseError ( format ! ( "Unable to get root as message: {err:?}" ) )
890
892
} ) ?;
891
893
// message header is a Schema, so read it
892
894
let ipc_schema: crate :: Schema = message. header_as_schema ( ) . ok_or_else ( || {
893
- ArrowError :: IoError ( "Unable to read IPC message as schema" . to_string ( ) )
895
+ ArrowError :: ParseError ( "Unable to read IPC message as schema" . to_string ( ) )
894
896
} ) ?;
895
897
let schema = crate :: convert:: fb_to_schema ( ipc_schema) ;
896
898
@@ -965,16 +967,16 @@ impl<R: Read> StreamReader<R> {
965
967
966
968
let vecs = & meta_buffer. to_vec ( ) ;
967
969
let message = crate :: root_as_message ( vecs) . map_err ( |err| {
968
- ArrowError :: IoError ( format ! ( "Unable to get root as message: {err:?}" ) )
970
+ ArrowError :: ParseError ( format ! ( "Unable to get root as message: {err:?}" ) )
969
971
} ) ?;
970
972
971
973
match message. header_type ( ) {
972
- crate :: MessageHeader :: Schema => Err ( ArrowError :: IoError (
974
+ crate :: MessageHeader :: Schema => Err ( ArrowError :: IpcError (
973
975
"Not expecting a schema when messages are read" . to_string ( ) ,
974
976
) ) ,
975
977
crate :: MessageHeader :: RecordBatch => {
976
978
let batch = message. header_as_record_batch ( ) . ok_or_else ( || {
977
- ArrowError :: IoError (
979
+ ArrowError :: IpcError (
978
980
"Unable to read IPC message as record batch" . to_string ( ) ,
979
981
)
980
982
} ) ?;
@@ -986,7 +988,7 @@ impl<R: Read> StreamReader<R> {
986
988
}
987
989
crate :: MessageHeader :: DictionaryBatch => {
988
990
let batch = message. header_as_dictionary_batch ( ) . ok_or_else ( || {
989
- ArrowError :: IoError (
991
+ ArrowError :: IpcError (
990
992
"Unable to read IPC message as dictionary batch" . to_string ( ) ,
991
993
)
992
994
} ) ?;
@@ -1004,7 +1006,7 @@ impl<R: Read> StreamReader<R> {
1004
1006
crate :: MessageHeader :: NONE => {
1005
1007
Ok ( None )
1006
1008
}
1007
- t => Err ( ArrowError :: IoError (
1009
+ t => Err ( ArrowError :: InvalidArgumentError (
1008
1010
format ! ( "Reading types other than record batches not yet supported, unable to read {t:?} " )
1009
1011
) ) ,
1010
1012
}
0 commit comments