Grounds
    Preparing search index...

    Class DecodeError

    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.

    Handling specific decode errors:

    import { decode, DecodeErrorCode } from '@grounds/core';

    const bytes = new Uint8Array([0x02]); // U8 but missing value byte

    decode(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:

    • Wire format violations (INVALID_TYPE_CODE, INVALID_LENGTH)
    • Data corruption (INVALID_UTF8, UNEXPECTED_EOF)
    • Constraint violations (UNSORTED_FIELDS, DUPLICATE_MAP_KEY)

    Hierarchy

    • Error
      • DecodeError
    Index

    Constructors

    Properties

    name: "DecodeError"

    Methods

    • Parameters

      • expected: number
      • available: number

      Returns DecodeError

    • Parameters

      • previousId: number
      • currentId: number

      Returns DecodeError

    • Parameters

      • declaredLength: number
      • actualLength: number

      Returns DecodeError