diff --git a/src/IO/BrotliReadBuffer.cpp b/src/IO/BrotliReadBuffer.cpp index 56ef2b5446b..1863cef8a39 100644 --- a/src/IO/BrotliReadBuffer.cpp +++ b/src/IO/BrotliReadBuffer.cpp @@ -3,6 +3,7 @@ #if USE_BROTLI # include # include "BrotliReadBuffer.h" +# include namespace DB { @@ -60,7 +61,10 @@ bool BrotliReadBuffer::nextImpl() if (brotli->result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT && (!in_available || in->eof())) { - throw Exception(ErrorCodes::BROTLI_READ_FAILED, "brotli decode error"); + throw Exception( + ErrorCodes::BROTLI_READ_FAILED, + "brotli decode error{}", + getExceptionEntryWithFileName(*in)); } out_capacity = internal_buffer.size(); @@ -83,13 +87,19 @@ bool BrotliReadBuffer::nextImpl() } else { - throw Exception(ErrorCodes::BROTLI_READ_FAILED, "brotli decode error"); + throw Exception( + ErrorCodes::BROTLI_READ_FAILED, + "brotli decode error{}", + getExceptionEntryWithFileName(*in)); } } if (brotli->result == BROTLI_DECODER_RESULT_ERROR) { - throw Exception(ErrorCodes::BROTLI_READ_FAILED, "brotli decode error"); + throw Exception( + ErrorCodes::BROTLI_READ_FAILED, + "brotli decode error{}", + getExceptionEntryWithFileName(*in)); } return true; diff --git a/src/IO/Bzip2ReadBuffer.cpp b/src/IO/Bzip2ReadBuffer.cpp index 9970edcbcf3..45ce8f45232 100644 --- a/src/IO/Bzip2ReadBuffer.cpp +++ b/src/IO/Bzip2ReadBuffer.cpp @@ -3,6 +3,7 @@ #if USE_BZIP2 # include # include +# include namespace DB { @@ -118,13 +119,17 @@ bool Bzip2ReadBuffer::nextImpl() if (ret != BZ_OK) throw Exception( ErrorCodes::BZIP2_STREAM_DECODER_FAILED, - "bzip2 stream decoder failed: error code: {}", - ret); + "bzip2 stream decoder failed: error code: {}{}", + ret, + getExceptionEntryWithFileName(*in)); if (in->eof()) { eof_flag = true; - throw Exception(ErrorCodes::UNEXPECTED_END_OF_FILE, "Unexpected end of bzip2 archive"); + throw Exception( + ErrorCodes::UNEXPECTED_END_OF_FILE, + "Unexpected end of bzip2 archive{}", + getExceptionEntryWithFileName(*in)); } return true; diff --git a/src/IO/HadoopSnappyReadBuffer.cpp b/src/IO/HadoopSnappyReadBuffer.cpp index 6ba31997b37..577367e5607 100644 --- a/src/IO/HadoopSnappyReadBuffer.cpp +++ b/src/IO/HadoopSnappyReadBuffer.cpp @@ -11,6 +11,8 @@ #include "HadoopSnappyReadBuffer.h" +#include + namespace DB { namespace ErrorCodes @@ -196,7 +198,11 @@ bool HadoopSnappyReadBuffer::nextImpl() if (decoder->result == Status::NEEDS_MORE_INPUT && (!in_available || in->eof())) { - throw Exception(ErrorCodes::SNAPPY_UNCOMPRESS_FAILED, "hadoop snappy decode error: {}", statusToString(decoder->result)); + throw Exception( + ErrorCodes::SNAPPY_UNCOMPRESS_FAILED, + "hadoop snappy decode error: {}{}", + statusToString(decoder->result), + getExceptionEntryWithFileName(*in)); } out_capacity = internal_buffer.size(); @@ -221,7 +227,11 @@ bool HadoopSnappyReadBuffer::nextImpl() } else if (decoder->result == Status::INVALID_INPUT || decoder->result == Status::BUFFER_TOO_SMALL) { - throw Exception(ErrorCodes::SNAPPY_UNCOMPRESS_FAILED, "hadoop snappy decode error: {}", statusToString(decoder->result)); + throw Exception( + ErrorCodes::SNAPPY_UNCOMPRESS_FAILED, + "hadoop snappy decode error: {}{}", + statusToString(decoder->result), + getExceptionEntryWithFileName(*in)); } return true; } diff --git a/src/IO/LZMAInflatingReadBuffer.cpp b/src/IO/LZMAInflatingReadBuffer.cpp index 6d40dafd517..a6f3c74ae73 100644 --- a/src/IO/LZMAInflatingReadBuffer.cpp +++ b/src/IO/LZMAInflatingReadBuffer.cpp @@ -1,4 +1,5 @@ #include +#include namespace DB { @@ -78,18 +79,20 @@ bool LZMAInflatingReadBuffer::nextImpl() { throw Exception( ErrorCodes::LZMA_STREAM_DECODER_FAILED, - "lzma decoder finished, but input stream has not exceeded: error code: {}; lzma version: {}", + "lzma decoder finished, but input stream has not exceeded: error code: {}; lzma version: {}{}", ret, - LZMA_VERSION_STRING); + LZMA_VERSION_STRING, + getExceptionEntryWithFileName(*in)); } } if (ret != LZMA_OK) throw Exception( ErrorCodes::LZMA_STREAM_DECODER_FAILED, - "lzma_stream_decoder failed: error code: error codeL {}; lzma version: {}", + "lzma_stream_decoder failed: error code: error code {}; lzma version: {}{}", ret, - LZMA_VERSION_STRING); + LZMA_VERSION_STRING, + getExceptionEntryWithFileName(*in)); return true; } diff --git a/src/IO/Lz4InflatingReadBuffer.cpp b/src/IO/Lz4InflatingReadBuffer.cpp index 049f3a4d15a..eaa71048e70 100644 --- a/src/IO/Lz4InflatingReadBuffer.cpp +++ b/src/IO/Lz4InflatingReadBuffer.cpp @@ -1,4 +1,5 @@ #include +#include namespace DB { @@ -72,9 +73,10 @@ bool Lz4InflatingReadBuffer::nextImpl() if (LZ4F_isError(ret)) throw Exception( ErrorCodes::LZ4_DECODER_FAILED, - "LZ4 decompression failed. LZ4F version: {}. Error: {}", + "LZ4 decompression failed. LZ4F version: {}. Error: {}{}", LZ4F_VERSION, - LZ4F_getErrorName(ret)); + LZ4F_getErrorName(ret), + getExceptionEntryWithFileName(*in)); if (in->eof()) { diff --git a/src/IO/WithFileName.cpp b/src/IO/WithFileName.cpp index 6ecb3671ca0..0ec9ed5dd53 100644 --- a/src/IO/WithFileName.cpp +++ b/src/IO/WithFileName.cpp @@ -26,4 +26,14 @@ String getFileNameFromReadBuffer(const ReadBuffer & in) return getFileName(in); } +String getExceptionEntryWithFileName(const ReadBuffer & in) +{ + auto filename = getFileNameFromReadBuffer(in); + + if (filename.empty()) + return ""; + + return "; While reading from: " + filename; +} + } diff --git a/src/IO/WithFileName.h b/src/IO/WithFileName.h index d770634e738..595f1a768c5 100644 --- a/src/IO/WithFileName.h +++ b/src/IO/WithFileName.h @@ -14,5 +14,6 @@ public: }; String getFileNameFromReadBuffer(const ReadBuffer & in); +String getExceptionEntryWithFileName(const ReadBuffer & in); } diff --git a/src/IO/ZlibInflatingReadBuffer.cpp b/src/IO/ZlibInflatingReadBuffer.cpp index 09e4fce7c4c..b43dda1bfcc 100644 --- a/src/IO/ZlibInflatingReadBuffer.cpp +++ b/src/IO/ZlibInflatingReadBuffer.cpp @@ -1,5 +1,5 @@ #include - +#include namespace DB { @@ -99,14 +99,22 @@ bool ZlibInflatingReadBuffer::nextImpl() { rc = inflateReset(&zstr); if (rc != Z_OK) - throw Exception(ErrorCodes::ZLIB_INFLATE_FAILED, "inflateReset failed: {}", zError(rc)); + throw Exception( + ErrorCodes::ZLIB_INFLATE_FAILED, + "inflateReset failed: {}{}", + zError(rc), + getExceptionEntryWithFileName(*in)); return true; } } /// If it is not end and not OK, something went wrong, throw exception if (rc != Z_OK) - throw Exception(ErrorCodes::ZLIB_INFLATE_FAILED, "inflate failed: {}", zError(rc)); + throw Exception( + ErrorCodes::ZLIB_INFLATE_FAILED, + "inflate failed: {}{}", + zError(rc), + getExceptionEntryWithFileName(*in)); } while (working_buffer.empty()); diff --git a/src/IO/ZstdInflatingReadBuffer.cpp b/src/IO/ZstdInflatingReadBuffer.cpp index 6f5c8b4dc71..2b663ec7145 100644 --- a/src/IO/ZstdInflatingReadBuffer.cpp +++ b/src/IO/ZstdInflatingReadBuffer.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -61,12 +62,13 @@ bool ZstdInflatingReadBuffer::nextImpl() { throw Exception( ErrorCodes::ZSTD_DECODER_FAILED, - "ZSTD stream decoding failed: error '{}'{}; ZSTD version: {}", + "ZSTD stream decoding failed: error '{}'{}; ZSTD version: {}{}", ZSTD_getErrorName(ret), ZSTD_error_frameParameter_windowTooLarge == ret ? ". You can increase the maximum window size with the 'zstd_window_log_max' setting in ClickHouse. Example: 'SET zstd_window_log_max = 31'" : "", - ZSTD_VERSION_STRING); + ZSTD_VERSION_STRING, + getExceptionEntryWithFileName(*in)); } /// Check that something has changed after decompress (input or output position)