@@ -125,21 +125,24 @@ impl ColumnarReader {
125125 // Iterate over the columns in a sorted way
126126 pub fn iter_columns (
127127 & self ,
128- ) -> io:: Result < impl Iterator < Item = ( String , DynamicColumnHandle ) > + ' _ > {
128+ ) -> io:: Result < impl Iterator < Item = io :: Result < ( String , DynamicColumnHandle ) > > + ' _ > {
129129 let mut stream = self . column_dictionary . stream ( ) ?;
130130 Ok ( std:: iter:: from_fn ( move || {
131131 if stream. advance ( ) {
132132 let key_bytes: & [ u8 ] = stream. key ( ) ;
133133 let column_code: u8 = key_bytes. last ( ) . cloned ( ) . unwrap ( ) ;
134- // TODO Error Handling. The API gets quite ugly when returning the error here, so
135- // instead we could just check the first N columns upfront.
136- let column_type: ColumnType = ColumnType :: try_from_code ( column_code)
137- . map_err ( |_| io_invalid_data ( format ! ( "Unknown column code `{column_code}`" ) ) )
138- . unwrap ( ) ;
134+ let column_type = match ColumnType :: try_from_code ( column_code) {
135+ Ok ( column_type) => column_type,
136+ Err ( _) => {
137+ return Some ( Err ( io_invalid_data ( format ! (
138+ "Unknown column code `{column_code}`"
139+ ) ) ) ) ;
140+ }
141+ } ;
139142 let range = stream. value ( ) . clone ( ) ;
140143 let column_name =
141- // The last two bytes are respectively the 0u8 separator and the column_type.
142- String :: from_utf8_lossy ( & key_bytes[ ..key_bytes. len ( ) - 2 ] ) . to_string ( ) ;
144+ // The last two bytes are respectively the 0u8 separator and the column_type.
145+ String :: from_utf8_lossy ( & key_bytes[ ..key_bytes. len ( ) - 2 ] ) . to_string ( ) ;
143146 let file_slice = self
144147 . column_data
145148 . slice ( range. start as usize ..range. end as usize ) ;
@@ -148,15 +151,15 @@ impl ColumnarReader {
148151 column_type,
149152 format_version : self . format_version ,
150153 } ;
151- Some ( ( column_name, column_handle) )
154+ Some ( Ok ( ( column_name, column_handle) ) )
152155 } else {
153156 None
154157 }
155158 } ) )
156159 }
157160
158161 pub fn list_columns ( & self ) -> io:: Result < Vec < ( String , DynamicColumnHandle ) > > {
159- Ok ( self . iter_columns ( ) ?. collect ( ) )
162+ self . iter_columns ( ) ?. collect ( )
160163 }
161164
162165 pub async fn read_columns_async (
0 commit comments