Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception message for ZSTD #48552

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/IO/ZstdDeflatingAppendableWriteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ ZstdDeflatingAppendableWriteBuffer::ZstdDeflatingAppendableWriteBuffer(
{
cctx = ZSTD_createCCtx();
if (cctx == nullptr)
throw Exception(ErrorCodes::ZSTD_ENCODER_FAILED, "zstd stream encoder init failed: zstd version: {}", ZSTD_VERSION_STRING);
throw Exception(ErrorCodes::ZSTD_ENCODER_FAILED, "ZSTD stream encoder init failed: ZSTD version: {}", ZSTD_VERSION_STRING);
size_t ret = ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, compression_level);
if (ZSTD_isError(ret))
throw Exception(ErrorCodes::ZSTD_ENCODER_FAILED,
"zstd stream encoder option setting failed: error code: {}; zstd version: {}",
"ZSTD stream encoder option setting failed: error code: {}; zstd version: {}",
ret, ZSTD_VERSION_STRING);

input = {nullptr, 0, 0};
Expand Down Expand Up @@ -64,7 +64,7 @@ void ZstdDeflatingAppendableWriteBuffer::nextImpl()
if (ZSTD_isError(compression_result))
throw Exception(
ErrorCodes::ZSTD_ENCODER_FAILED,
"Zstd stream encoding failed: error code: {}; zstd version: {}",
"ZSTD stream decoding failed: error code: {}; ZSTD version: {}",
ZSTD_getErrorName(compression_result), ZSTD_VERSION_STRING);

first_write = false;
Expand Down Expand Up @@ -138,7 +138,7 @@ void ZstdDeflatingAppendableWriteBuffer::finalizeBefore()
{
if (ZSTD_isError(remaining))
throw Exception(ErrorCodes::ZSTD_ENCODER_FAILED,
"Zstd stream encoder end failed: error: '{}' zstd version: {}",
"ZSTD stream encoder end failed: error: '{}' ZSTD version: {}",
ZSTD_getErrorName(remaining), ZSTD_VERSION_STRING);

remaining = ZSTD_compressStream2(cctx, &output, &input, ZSTD_e_end);
Expand Down
2 changes: 1 addition & 1 deletion src/IO/ZstdDeflatingWriteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ZstdDeflatingWriteBuffer::nextImpl()
if (ZSTD_isError(compression_result))
throw Exception(
ErrorCodes::ZSTD_ENCODER_FAILED,
"Zstd stream encoding failed: error: '{}'; zstd version: {}",
"ZSTD stream encoding failed: error: '{}'; zstd version: {}",
ZSTD_getErrorName(compression_result), ZSTD_VERSION_STRING);

out->position() = out->buffer().begin() + output.pos;
Expand Down
15 changes: 11 additions & 4 deletions src/IO/ZstdInflatingReadBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <IO/ZstdInflatingReadBuffer.h>
#include <zstd_errors.h>


namespace DB
Expand Down Expand Up @@ -56,11 +57,17 @@ bool ZstdInflatingReadBuffer::nextImpl()

/// Decompress data and check errors.
size_t ret = ZSTD_decompressStream(dctx, &output, &input);
if (ZSTD_isError(ret))
if (ZSTD_getErrorCode(ret))
{
throw Exception(
ErrorCodes::ZSTD_DECODER_FAILED,
"Zstd stream encoding failed: error '{}'; zstd version: {}",
ZSTD_getErrorName(ret), ZSTD_VERSION_STRING);
ErrorCodes::ZSTD_DECODER_FAILED,
"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);
}

/// Check that something has changed after decompress (input or output position)
assert(in->eof() || output.pos > 0 || in->position() < in->buffer().begin() + input.pos);
Expand Down