Error type for decoding failures with structured error codes.
Provides factory methods for specific decode failures and includes a code property for programmatic error classification. Use the code property to distinguish error types.
code
Handling specific decode errors:
import { decode, DecodeErrorCode } from '@grounds/core';const bytes = new Uint8Array([0x02]); // U8 but missing value bytedecode(bytes).match( (value) => console.log('Decoded:', value), (error) => { switch (error.code) { case 'UNEXPECTED_EOF': console.error('Truncated data'); break; case 'INVALID_UTF8': console.error('Bad string encoding'); break; default: console.error('Other error:', error.message); } }); Copy
import { decode, DecodeErrorCode } from '@grounds/core';const bytes = new Uint8Array([0x02]); // U8 but missing value bytedecode(bytes).match( (value) => console.log('Decoded:', value), (error) => { switch (error.code) { case 'UNEXPECTED_EOF': console.error('Truncated data'); break; case 'INVALID_UTF8': console.error('Bad string encoding'); break; default: console.error('Other error:', error.message); } });
DecodeError.code enables robust error handling for different failure modes:
Readonly
Static
Error type for decoding failures with structured error codes.
Provides factory methods for specific decode failures and includes a
codeproperty for programmatic error classification. Use the code property to distinguish error types.Example
Handling specific decode errors:
Remarks
DecodeError.code enables robust error handling for different failure modes: