@@ -192,7 +192,8 @@ void ColumnReader::InitializeRead(idx_t row_group_idx_p, const vector<ColumnChun
192192 D_ASSERT (chunk->__isset .meta_data );
193193
194194 if (chunk->__isset .file_path ) {
195- throw std::runtime_error (" Only inlined data files are supported (no references)" );
195+ throw InvalidInputException (" Failed to read file \" %s\" : Only inlined data files are supported (no references)" ,
196+ Reader ().GetFileName ());
196197 }
197198
198199 // ugh. sometimes there is an extra offset for the dict. sometimes it's wrong.
@@ -252,7 +253,7 @@ void ColumnReader::PrepareRead(optional_ptr<const TableFilter> filter, optional_
252253 }
253254 // some basic sanity check
254255 if (page_hdr.compressed_page_size < 0 || page_hdr.uncompressed_page_size < 0 ) {
255- throw std::runtime_error ( " Page sizes can't be < 0" );
256+ throw InvalidInputException ( " Failed to read file \" %s \" : Page sizes can't be < 0" , Reader (). GetFileName () );
256257 }
257258
258259 if (PageIsFilteredOut (page_hdr)) {
@@ -273,7 +274,8 @@ void ColumnReader::PrepareRead(optional_ptr<const TableFilter> filter, optional_
273274 PreparePage (page_hdr);
274275 auto dictionary_size = page_hdr.dictionary_page_header .num_values ;
275276 if (dictionary_size < 0 ) {
276- throw std::runtime_error (" Invalid dictionary page header (num_values < 0)" );
277+ throw InvalidInputException (" Failed to read file \" %s\" : Invalid dictionary page header (num_values < 0)" ,
278+ Reader ().GetFileName ());
277279 }
278280 dictionary_decoder.InitializeDictionary (dictionary_size, filter, filter_state, HasDefines ());
279281 break ;
@@ -297,7 +299,7 @@ void ColumnReader::PreparePageV2(PageHeader &page_hdr) {
297299 }
298300 if (chunk->meta_data .codec == CompressionCodec::UNCOMPRESSED) {
299301 if (page_hdr.compressed_page_size != page_hdr.uncompressed_page_size ) {
300- throw std::runtime_error ( " Page size mismatch" );
302+ throw InvalidInputException ( " Failed to read file \" %s \" : Page size mismatch" , Reader (). GetFileName () );
301303 }
302304 uncompressed = true ;
303305 }
@@ -310,8 +312,10 @@ void ColumnReader::PreparePageV2(PageHeader &page_hdr) {
310312 auto uncompressed_bytes = page_hdr.data_page_header_v2 .repetition_levels_byte_length +
311313 page_hdr.data_page_header_v2 .definition_levels_byte_length ;
312314 if (uncompressed_bytes > page_hdr.uncompressed_page_size ) {
313- throw std::runtime_error (" Page header inconsistency, uncompressed_page_size needs to be larger than "
314- " repetition_levels_byte_length + definition_levels_byte_length" );
315+ throw InvalidInputException (
316+ " Failed to read file \" %s\" : header inconsistency, uncompressed_page_size needs to be larger than "
317+ " repetition_levels_byte_length + definition_levels_byte_length" ,
318+ Reader ().GetFileName ());
315319 }
316320 reader.ReadData (*protocol, block->ptr , uncompressed_bytes);
317321
@@ -368,7 +372,8 @@ void ColumnReader::DecompressInternal(CompressionCodec::type codec, const_data_p
368372 duckdb_lz4::LZ4_decompress_safe (const_char_ptr_cast (src), char_ptr_cast (dst),
369373 UnsafeNumericCast<int32_t >(src_size), UnsafeNumericCast<int32_t >(dst_size));
370374 if (res != NumericCast<int >(dst_size)) {
371- throw std::runtime_error (" LZ4 decompression failure" );
375+ throw InvalidInputException (" Failed to read file \" %s\" : LZ4 decompression failure" ,
376+ Reader ().GetFileName ());
372377 }
373378 break ;
374379 }
@@ -377,22 +382,27 @@ void ColumnReader::DecompressInternal(CompressionCodec::type codec, const_data_p
377382 size_t uncompressed_size = 0 ;
378383 auto res = duckdb_snappy::GetUncompressedLength (const_char_ptr_cast (src), src_size, &uncompressed_size);
379384 if (!res) {
380- throw std::runtime_error (" Snappy decompression failure" );
385+ throw InvalidInputException (" Failed to read file \" %s\" : Snappy decompression failure" ,
386+ Reader ().GetFileName ());
381387 }
382388 if (uncompressed_size != dst_size) {
383- throw std::runtime_error (" Snappy decompression failure: Uncompressed data size mismatch" );
389+ throw InvalidInputException (
390+ " Failed to read file \" %s\" : Snappy decompression failure: Uncompressed data size mismatch" ,
391+ Reader ().GetFileName ());
384392 }
385393 }
386394 auto res = duckdb_snappy::RawUncompress (const_char_ptr_cast (src), src_size, char_ptr_cast (dst));
387395 if (!res) {
388- throw std::runtime_error (" Snappy decompression failure" );
396+ throw InvalidInputException (" Failed to read file \" %s\" : Snappy decompression failure" ,
397+ Reader ().GetFileName ());
389398 }
390399 break ;
391400 }
392401 case CompressionCodec::ZSTD: {
393402 auto res = duckdb_zstd::ZSTD_decompress (dst, dst_size, src, src_size);
394403 if (duckdb_zstd::ZSTD_isError (res) || res != dst_size) {
395- throw std::runtime_error (" ZSTD Decompression failure" );
404+ throw InvalidInputException (" Failed to read file \" %s\" : ZSTD Decompression failure" ,
405+ Reader ().GetFileName ());
396406 }
397407 break ;
398408 }
@@ -405,7 +415,8 @@ void ColumnReader::DecompressInternal(CompressionCodec::type codec, const_data_p
405415 auto res = duckdb_brotli::BrotliDecoderDecompressStream (state, &src_size_size_t , &src, &dst_size_size_t , &dst,
406416 &total_out);
407417 if (res != duckdb_brotli::BROTLI_DECODER_RESULT_SUCCESS) {
408- throw std::runtime_error (" Brotli Decompression failure" );
418+ throw InvalidInputException (" Failed to read file \" %s\" : Brotli Decompression failure" ,
419+ Reader ().GetFileName ());
409420 }
410421 duckdb_brotli::BrotliDecoderDestroyInstance (state);
411422 break ;
@@ -414,18 +425,21 @@ void ColumnReader::DecompressInternal(CompressionCodec::type codec, const_data_p
414425 default : {
415426 duckdb::stringstream codec_name;
416427 codec_name << codec;
417- throw std::runtime_error (" Unsupported compression codec \" " + codec_name.str () +
418- " \" . Supported options are uncompressed, brotli, gzip, lz4_raw, snappy or zstd" );
428+ throw InvalidInputException (" Failed to read file \" %s\" : Unsupported compression codec \" %s\" . Supported "
429+ " options are uncompressed, brotli, gzip, lz4_raw, snappy or zstd" ,
430+ Reader ().GetFileName (), codec_name.str ());
419431 }
420432 }
421433}
422434
423435void ColumnReader::PrepareDataPage (PageHeader &page_hdr) {
424436 if (page_hdr.type == PageType::DATA_PAGE && !page_hdr.__isset .data_page_header ) {
425- throw std::runtime_error (" Missing data page header from data page" );
437+ throw InvalidInputException (" Failed to read file \" %s\" : Missing data page header from data page" ,
438+ Reader ().GetFileName ());
426439 }
427440 if (page_hdr.type == PageType::DATA_PAGE_V2 && !page_hdr.__isset .data_page_header_v2 ) {
428- throw std::runtime_error (" Missing data page header from data page v2" );
441+ throw InvalidInputException (" Failed to read file \" %s\" : Missing data page header from data page v2" ,
442+ Reader ().GetFileName ());
429443 }
430444
431445 bool is_v1 = page_hdr.type == PageType::DATA_PAGE;
@@ -492,7 +506,7 @@ void ColumnReader::PrepareDataPage(PageHeader &page_hdr) {
492506 break ;
493507
494508 default :
495- throw std::runtime_error ( " Unsupported page encoding" );
509+ throw InvalidInputException ( " Failed to read file \" %s \" : Unsupported page encoding" , Reader (). GetFileName () );
496510 }
497511}
498512
0 commit comments