Add file name to exception raised during decompression

This commit is contained in:
Nikolay Degterinsky 2023-04-27 02:36:50 +00:00
parent ed97e46d41
commit 111fb4b8a9
9 changed files with 70 additions and 19 deletions

View File

@ -3,6 +3,7 @@
#if USE_BROTLI
# include <brotli/decode.h>
# include "BrotliReadBuffer.h"
# include <IO/WithFileName.h>
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;

View File

@ -3,6 +3,7 @@
#if USE_BZIP2
# include <IO/Bzip2ReadBuffer.h>
# include <bzlib.h>
# include <IO/WithFileName.h>
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;

View File

@ -11,6 +11,8 @@
#include "HadoopSnappyReadBuffer.h"
#include <IO/WithFileName.h>
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;
}

View File

@ -1,4 +1,5 @@
#include <IO/LZMAInflatingReadBuffer.h>
#include <IO/WithFileName.h>
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;
}

View File

@ -1,4 +1,5 @@
#include <IO/Lz4InflatingReadBuffer.h>
#include <IO/WithFileName.h>
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())
{

View File

@ -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;
}
}

View File

@ -14,5 +14,6 @@ public:
};
String getFileNameFromReadBuffer(const ReadBuffer & in);
String getExceptionEntryWithFileName(const ReadBuffer & in);
}

View File

@ -1,5 +1,5 @@
#include <IO/ZlibInflatingReadBuffer.h>
#include <IO/WithFileName.h>
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());

View File

@ -1,4 +1,5 @@
#include <IO/ZstdInflatingReadBuffer.h>
#include <IO/WithFileName.h>
#include <zstd_errors.h>
@ -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)