Grounds
    Preparing search index...

    Class EncodeError

    Error type for encoding failures.

    Provides factory methods for specific error conditions encountered during encoding. All EncodeError instances include a descriptive message property.

    Handling encode errors:

    import { encode, Struct, U8 } from '@grounds/core';

    const invalidStruct = Struct(new Map([
    [5, U8(1)],
    [2, U8(2)] // Out of order! Should be sorted by field ID
    ]));

    encode(invalidStruct).match(
    (bytes) => console.log('Encoded'),
    (error) => {
    console.error(error.message); // "Struct fields must be sorted"
    }
    );

    Encode errors indicate programmer errors (invalid input structure), not I/O failures. Common errors include unsorted struct fields, invalid field IDs, and unsupported types.

    Hierarchy

    • Error
      • EncodeError
    Index

    Constructors

    • Parameters

      • message: string

      Returns EncodeError

    Properties

    name: "EncodeError"

    Methods

    • Parameters

      • previousId: number
      • currentId: number

      Returns EncodeError

    • Error for integer values that exceed type-specific bounds.

      This error is part of encoder defense-in-depth validation: even if a value somehow bypasses value constructor validation, the encoder re-validates integer ranges before writing bytes. This ensures wire format correctness.

      Parameters

      • typeName: string

        The integer type name (e.g., "u8", "i64")

      • value: number | bigint

        The out-of-range value that failed validation

      • min: number | bigint

        The minimum valid value for the type

      • max: number | bigint

        The maximum valid value for the type

      Returns EncodeError

      EncodeError describing the range violation

    • Error for non-integer number values in integer types.

      This error is part of encoder defense-in-depth validation: the encoder validates that floating-point numbers like 3.14 are rejected for integer type codes. This ensures only whole numbers are encoded in integer fields.

      Parameters

      • typeName: string

        The integer type name (e.g., "u32", "i64")

      • value: number

        The non-integer number that failed validation

      Returns EncodeError

      EncodeError describing the non-integer value