size_t value that can represent either a successful result or an error code. The error handling API provides functions to detect and interpret these errors.
Error Detection
ZSTD_isError()
Test if a function result indicates an error.result- Return value from a Zstandard function
1if error0if success
ZSTD_getErrorName()
Get readable error message from a function result.result- Return value from a Zstandard function
ZSTD_getErrorCode()
Convert a function result into an error code enum value.functionResult- Return value from a Zstandard function
ZSTD_ErrorCode enum value that can be compared against error codes
Example:
Error Codes
TheZSTD_ErrorCode enum defines all possible error conditions. Error code values are pinned down since v1.3.1.
Stable Error Codes (< 100)
These error codes are stable and safe to rely on:General Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_no_error | 0 | No error |
ZSTD_error_GENERIC | 1 | Generic error |
Format Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_prefix_unknown | 10 | Unknown frame prefix |
ZSTD_error_version_unsupported | 12 | Unsupported version |
ZSTD_error_frameParameter_unsupported | 14 | Unsupported frame parameter |
ZSTD_error_frameParameter_windowTooLarge | 16 | Window size too large |
Data Integrity Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_corruption_detected | 20 | Data corruption detected |
ZSTD_error_checksum_wrong | 22 | Checksum verification failed |
ZSTD_error_literals_headerWrong | 24 | Literals header is wrong |
Dictionary Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_dictionary_corrupted | 30 | Dictionary is corrupted |
ZSTD_error_dictionary_wrong | 32 | Wrong dictionary used |
ZSTD_error_dictionaryCreation_failed | 34 | Dictionary creation failed |
Parameter Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_parameter_unsupported | 40 | Parameter not supported |
ZSTD_error_parameter_combination_unsupported | 41 | Parameter combination not supported |
ZSTD_error_parameter_outOfBound | 42 | Parameter value out of bounds |
ZSTD_error_tableLog_tooLarge | 44 | Table log too large |
ZSTD_error_maxSymbolValue_tooLarge | 46 | Max symbol value too large |
ZSTD_error_maxSymbolValue_tooSmall | 48 | Max symbol value too small |
ZSTD_error_cannotProduce_uncompressedBlock | 49 | Cannot produce uncompressed block |
ZSTD_error_stabilityCondition_notRespected | 50 | Stability condition not respected |
State Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_stage_wrong | 60 | Wrong stage for this operation |
ZSTD_error_init_missing | 62 | Initialization missing |
ZSTD_error_memory_allocation | 64 | Memory allocation failed |
ZSTD_error_workSpace_tooSmall | 66 | Workspace too small |
Size Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_dstSize_tooSmall | 70 | Destination buffer too small |
ZSTD_error_srcSize_wrong | 72 | Source size is wrong |
ZSTD_error_dstBuffer_null | 74 | Destination buffer is NULL |
Progress Errors
| Code | Value | Description |
|---|---|---|
ZSTD_error_noForwardProgress_destFull | 80 | No forward progress (destination full) |
ZSTD_error_noForwardProgress_inputEmpty | 82 | No forward progress (input empty) |
Experimental Error Codes (≥ 100)
These error codes are not stable and may change in future versions:| Code | Value | Description |
|---|---|---|
ZSTD_error_frameIndex_tooLarge | 100 | Frame index too large |
ZSTD_error_seekableIO | 102 | Seekable I/O error |
ZSTD_error_dstBuffer_wrong | 104 | Destination buffer wrong |
ZSTD_error_srcBuffer_wrong | 105 | Source buffer wrong |
ZSTD_error_sequenceProducer_failed | 106 | Sequence producer failed |
ZSTD_error_externalSequences_invalid | 107 | External sequences invalid |
ZSTD_error_maxCode | 120 | Never use directly - marks end of enum |
ZSTD_error_maxCode directly as it can change. Always use ZSTD_isError() instead.
Error Handling Patterns
Basic Error Checking
Checking Specific Error Codes
Streaming Error Handling
Advanced Error Context
Best Practices
- Always check for errors - Most Zstandard functions can fail
- Use ZSTD_isError() - Never compare result values directly
- Log error messages - Use
ZSTD_getErrorName()for debugging - Handle common errors - Check for buffer size, corruption, and memory errors
- Clean up on error - Free allocated resources even when errors occur
- Use error codes for logic - Compare against
ZSTD_ErrorCodeenum for specific handling - Don’t rely on experimental codes - Only values < 100 are stable
See Also
- Compression Parameters - Setting compression options
- Memory Management - Buffer sizing and allocation