diff options
author | vnugent <public@vaughnnugent.com> | 2023-09-13 11:00:17 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-09-13 11:00:17 -0400 |
commit | cdeda79bc7d358c617b05b17d24f3f3c79689379 (patch) | |
tree | 387d05ff42725024579299dc3e941fa950722275 /lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs | |
parent | dcf6f9dc0143eb50b702eb7dcd9e5dadd140537c (diff) |
Overhaul cmake, fix some warnings, and reconfigure proper compiler options with hardware support
Diffstat (limited to 'lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs')
-rw-r--r-- | lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs b/lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs index 2793526..40ce336 100644 --- a/lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs +++ b/lib/Net.Compression/VNLib.Net.Compression/ThrowHelper.cs @@ -24,8 +24,6 @@ using System; -using VNLib.Utils; - namespace VNLib.Net.Compression { internal static class ThrowHelper @@ -43,6 +41,8 @@ namespace VNLib.Net.Compression ErrCompLevelNotSupported = -10, ErrInvalidInput = -11, ErrInvalidOutput = -12, + ErrCompressionFailed = -13, + ErrCompOverflow = -14, ErrGzInvalidState = -16, ErrGzOverflow = -17, @@ -55,37 +55,29 @@ namespace VNLib.Net.Compression /// </summary> /// <param name="result"></param> /// <exception cref="NativeCompressionException"></exception> - public static void ThrowIfError(ERRNO result) + public static void ThrowIfError(long result) { //Check for no error - if(result > 0) + if(result >= 0) { return; } - switch ((NativeErrorType)(int)result) + throw (NativeErrorType)result switch { - case NativeErrorType.ErrInvalidPtr: - throw new NativeCompressionException("A pointer to a compressor instance was null"); - case NativeErrorType.ErrOutOfMemory: - throw new NativeCompressionException("An operation falied because the system is out of memory"); - case NativeErrorType.ErrCompTypeNotSupported: - throw new NotSupportedException("The desired compression method is not supported by the native library"); - case NativeErrorType.ErrCompLevelNotSupported: - throw new NotSupportedException("The desired compression level is not supported by the native library"); - case NativeErrorType.ErrInvalidInput: - throw new NativeCompressionException("The input buffer was null and the input size was greater than 0"); - case NativeErrorType.ErrInvalidOutput: - throw new NativeCompressionException("The output buffer was null and the output size was greater than 0"); - case NativeErrorType.ErrGzInvalidState: - throw new NativeCompressionException("A gzip operation failed because the compressor state is invalid (null compressor pointer)"); - case NativeErrorType.ErrGzOverflow: - throw new NativeCompressionException("A gzip operation failed because the output buffer is too small"); - case NativeErrorType.ErrBrInvalidState: - throw new NativeCompressionException("A brotli operation failed because the compressor state is invalid (null compressor pointer)"); - default: - break; - } + NativeErrorType.ErrInvalidPtr => new NativeCompressionException("A pointer to a compressor instance was null"), + NativeErrorType.ErrOutOfMemory => new NativeCompressionException("An operation falied because the system is out of memory"), + NativeErrorType.ErrCompTypeNotSupported => new NotSupportedException("The desired compression method is not supported by the native library"), + NativeErrorType.ErrCompLevelNotSupported => new NotSupportedException("The desired compression level is not supported by the native library"), + NativeErrorType.ErrInvalidInput => new NativeCompressionException("The input buffer was null and the input size was greater than 0"), + NativeErrorType.ErrInvalidOutput => new NativeCompressionException("The output buffer was null and the output size was greater than 0"), + NativeErrorType.ErrGzInvalidState => new NativeCompressionException("A gzip operation failed because the compressor state is invalid (null compressor pointer)"), + NativeErrorType.ErrGzOverflow => new NativeCompressionException("A gzip operation failed because the output buffer is too small"), + NativeErrorType.ErrBrInvalidState => new NativeCompressionException("A brotli operation failed because the compressor state is invalid (null compressor pointer)"), + NativeErrorType.ErrCompOverflow => new OverflowException("A call to compress block or get block size failed because the library would cause an integer overflow processing your data"), + NativeErrorType.ErrCompressionFailed => new NativeCompressionException("An operation failes because the underlying implementation would cause a memory related error. State is considered corrupted"), + _ => new NativeCompressionException($"An unknown error occurred, code: 0x{result:x}"), + }; } } }
\ No newline at end of file |