[+] ICompressionStream::GetLastErrorString

[+] ICompressionStream::GetLastError
This commit is contained in:
Reece Wilson 2023-10-17 09:27:59 +01:00
parent fe36ee5fb2
commit 95643d6e19
13 changed files with 73 additions and 23 deletions

View File

@ -70,5 +70,17 @@ namespace Aurora::Compression
/// Compression only
virtual bool Finish() = 0;
/**
* @brief
* @return
*/
virtual AuOptional<int> GetLastError() = 0;
/**
* @brief
* @return
*/
virtual AuOptional<AuString> GetLastErrorString() = 0;
};
}

View File

@ -195,6 +195,29 @@ namespace Aurora::Compression
return this->pOutputBuffer_->allocSize;
}
AuOptional<int> BaseStream::GetLastError()
{
return this->optLastError_;
}
AuOptional<AuString> BaseStream::GetLastErrorString()
{
return this->optLastErrorString_;
}
void BaseStream::SetLastError(int i, const AuString &str)
{
this->optLastError_ = i;
this->optLastErrorString_ = str;
SysPushErrorMalformedData("Compression Error: {} {}", i, str);
}
void BaseStream::SetLastError(int i)
{
this->optLastError_ = i;
SysPushErrorMalformedData("Compression Error: {}", i);
}
bool BaseStream::Flush()
{
return false;

View File

@ -32,6 +32,12 @@ namespace Aurora::Compression
virtual AuUInt32 GetInternalBufferSize() override;
virtual AuOptional<int> GetLastError() override;
virtual AuOptional<AuString> GetLastErrorString() override;
void SetLastError(int i, const AuString &str);
void SetLastError(int i);
bool Write(const void *pDest, AuUInt32 dwLength);
bool Write2(const void *pDest, AuUInt32 dwLength);
@ -63,6 +69,8 @@ namespace Aurora::Compression
Memory::ByteBuffer _outbufferOwned;
AuThreadPrimitives::SpinLock _spinlock;
AuUInt32 uBufferSize_;
AuOptional<int> optLastError_;
AuString optLastErrorString_;
};
}

View File

@ -58,7 +58,7 @@ namespace Aurora::Compression
auto ret = BZ2_bzCompressInit(&this->ctx_, meta.uCompressionLevel, 0, 0);
if (ret < BZ_OK)
{
SysPushErrorMem("Error: {}", BShitToString(ret));
this->SetLastError(ret, BShitToString(ret));
return false;
}
this->bInit_ = true;
@ -147,7 +147,7 @@ namespace Aurora::Compression
auto ret = BZ2_bzCompress(&this->ctx_, type);
if (ret < BZ_OK)
{
SysPushErrorIO("Error: {}", BShitToString(ret));
this->SetLastError(ret, BShitToString(ret));
this->pReader_.reset();
return false;
}
@ -177,7 +177,7 @@ namespace Aurora::Compression
auto ret = BZ2_bzCompress(&this->ctx_, type);
if (ret < BZ_OK)
{
SysPushErrorIO("Error: {}", BShitToString(ret));
this->SetLastError(ret, BShitToString(ret));
this->pReader_.reset();
return false;
}

View File

@ -58,7 +58,7 @@ namespace Aurora::Compression
auto ret = BZ2_bzDecompressInit(&this->ctx_, 0, 0);
if (ret < BZ_OK)
{
SysPushErrorMem("Error: {}", BShitToString(ret));
this->SetLastError(ret, BShitToString(ret));
return false;
}
@ -97,7 +97,7 @@ namespace Aurora::Compression
auto ret = BZ2_bzDecompress(&this->ctx_);
if (ret < BZ_OK)
{
SysPushErrorIO("Error: {}", BShitToString(ret));
this->SetLastError(ret, BShitToString(ret));
this->pReader_.reset();
return AuMakePair(read, 0);
}

View File

@ -53,7 +53,6 @@ namespace Aurora::Compression
}
}
this->SetArray(this->din_);
this->SetOutArray(this->dout_);
return true;
@ -89,7 +88,7 @@ namespace Aurora::Compression
auto ret = BrotliDecoderDecompressStream(this->pState, &this->uAvailIn, (const uint8_t **)&this->pInBuffer, &outNext, &pOut, nullptr);
if (ret == BROTLI_DECODER_RESULT_ERROR)
{
SysPushErrorIO("Brotli Error");
this->SetLastError(ret, BrotliDecoderErrorString((BrotliDecoderErrorCode)ret));
this->pReader_.reset();
return AuMakePair(read, 0);
}

View File

@ -42,7 +42,7 @@ namespace Aurora::Compression
auto ret = deflateInit2(&this->ctx_, meta.uCompressionLevel, Z_DEFLATED, this->bits_, 8, Z_DEFAULT_STRATEGY);
if (ret < Z_OK)
{
SysPushErrorMem("Error: {}", ret);
this->SetLastError(ret, zError(ret));
return false;
}
this->init_ = true;
@ -84,7 +84,7 @@ namespace Aurora::Compression
auto ret = deflate(&this->ctx_, Z_NO_FLUSH);
if (ret < Z_OK)
{
SysPushErrorIO("Error: {}", zError(ret));
this->SetLastError(ret, zError(ret));
this->pReader_.reset();
return AuMakePair(read, 0);
}
@ -135,7 +135,7 @@ namespace Aurora::Compression
auto ret = deflate(&this->ctx_, Z_FULL_FLUSH);
if (ret < Z_OK)
{
SysPushErrorIO("Error: {}", zError(ret));
this->SetLastError(ret, zError(ret));
this->pReader_.reset();
return false;
}
@ -163,7 +163,7 @@ namespace Aurora::Compression
auto ret = deflate(&this->ctx_, type);
if (ret < Z_OK)
{
SysPushErrorIO("Error: {}", zError(ret));
this->SetLastError(ret, zError(ret));
this->pReader_.reset();
return false;
}

View File

@ -130,6 +130,7 @@ namespace Aurora::Compression
AuUInt32 bufferedBytes = LZ4F_compressEnd(cctxPtr, startPtr, meta.uInternalStreamSize - bytesRemInFrame, &options);
if (LZ4F_isError(bufferedBytes))
{
this->SetLastError(bufferedBytes);
this->bDead = true;
return false;
}
@ -180,6 +181,7 @@ namespace Aurora::Compression
if (LZ4F_isError(temp))
{
SysPushErrorGeneric("LZ4 internal stream size was too small. ingested too much data. must reset stream now");
this->SetLastError(temp);
bDead = true;
return {};
}

View File

@ -95,6 +95,7 @@ namespace Aurora::Compression
bytesRemInFrame = LZ4F_decompress(this->lz4Stream_, this->pBufferOut_.get(), &frameS2Ptr, this->pReadPtr_, &frameSPtr, &opts);
if (LZ4F_isError(bytesRemInFrame))
{
this->SetLastError(bytesRemInFrame);
return {};
}

View File

@ -74,7 +74,7 @@ namespace Aurora::Compression
if (ret != LZMA_OK)
{
SysPushErrorGeneric("LZMA Coder failure: {}", (int)ret);
this->SetLastError(ret);
AuResetMember(this->pReader_);
return false;
}
@ -133,7 +133,7 @@ namespace Aurora::Compression
if (ret != LZMA_OK &&
ret != LZMA_STREAM_END)
{
SysPushErrorIO("Error: {}", int(ret));
this->SetLastError(ret);
this->pReader_.reset();
return AuMakePair(read, 0);
}
@ -142,7 +142,7 @@ namespace Aurora::Compression
done += have;
if (!Write2(reinterpret_cast<const AuUInt8 *>(pMainDOut),
have))
have))
{
this->pReader_.reset();
SysPushErrorIO("Compression Out of Overhead");

View File

@ -60,7 +60,7 @@ namespace Aurora::Compression
if (ret != LZMA_OK)
{
SysPushErrorGeneric("LZMA Decoder failure: {}", (int)ret);
this->SetLastError(ret);
AuResetMember(this->pReader_);
return false;
}
@ -71,7 +71,7 @@ namespace Aurora::Compression
if (ret != LZMA_OK)
{
SysPushErrorGeneric("LZMA Decoder failure: {}", (int)ret);
this->SetLastError(ret);
AuResetMember(this->pReader_);
return false;
}
@ -119,7 +119,7 @@ namespace Aurora::Compression
if (ret != LZMA_OK &&
ret != LZMA_STREAM_END)
{
SysPushErrorIO("Error: {}", int(ret));
this->SetLastError(ret);
this->pReader_.reset();
return AuMakePair(read, 0);
}

View File

@ -49,6 +49,7 @@ namespace Aurora::Compression
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Invalid compression level");
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
@ -56,6 +57,7 @@ namespace Aurora::Compression
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Invalid option");
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
@ -65,6 +67,7 @@ namespace Aurora::Compression
if (ZSTD_isError(uRet))
{
SysPushErrorArg("ZSTD_c_strategy");
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
}
@ -79,7 +82,7 @@ namespace Aurora::Compression
uRet = ZSTD_CCtx_setParameter(this->cctx_, ZSTD_c_nbWorkers, AuMax(meta.uThreads, AuUInt8(1u)));
if (ZSTD_isError(uRet))
{
SysPushErrorArg();
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
}
@ -90,6 +93,7 @@ namespace Aurora::Compression
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Compressor argument assignment {} = {}", a, b);
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
}
@ -139,7 +143,7 @@ namespace Aurora::Compression
uRet = ZSTD_compressStream2(this->cctx_, &output, &this->input_, mode);
if (ZSTD_isError(uRet))
{
SysPushErrorIO("Compression error: {}", ZSTD_getErrorName(uRet));
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
this->uAvailableIn_ -= AuUInt32(output.pos);
this->pReader_.reset();
return AuMakePair(read, 0);
@ -192,7 +196,7 @@ namespace Aurora::Compression
uRet = ZSTD_compressStream2(this->cctx_, &output, &this->input_, ZSTD_e_flush);
if (ZSTD_isError(uRet))
{
SysPushErrorIO("Compression error: {}", ZSTD_getErrorName(uRet));
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
this->uAvailableIn_ -= AuUInt32(output.pos);
return {};
}
@ -240,12 +244,12 @@ namespace Aurora::Compression
uRet = ZSTD_endStream(this->cctx_, &output);
if (ZSTD_isError(uRet))
{
SysPushErrorIO("Compression error: {}", ZSTD_getErrorName(uRet));
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return {};
}
if (!Write(reinterpret_cast<const AuUInt8 *>(this->dout_),
AuUInt32(output.pos)))
AuUInt32(output.pos)))
{
SysPushErrorIO("Compression Out of Overhead");
return false;

View File

@ -49,6 +49,7 @@ namespace Aurora::Compression
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Decompressor argument assignment {} = {}", a, b);
this->SetLastError(uRet, ZSTD_getErrorName(uRet));
return false;
}
}
@ -90,7 +91,7 @@ namespace Aurora::Compression
auto ret = ZSTD_decompressStream(this->dctx_, &output, &this->input_);
if (ZSTD_isError(ret))
{
SysPushErrorIO("Decompression error: {}", ZSTD_getErrorName(ret));
this->SetLastError(ret, ZSTD_getErrorName(ret));
this->pReader_.reset();
return AuMakePair(read, 0);
}