clockworklabs/SpacetimeDB · error · ArgumentException

randomBytes must be exactly 4 bytes

Error message

randomBytes must be exactly 4 bytes

What it means

Error "randomBytes must be exactly 4 bytes" thrown in clockworklabs/SpacetimeDB.

Source

Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs:127

    /// </param>
    /// <exception cref="InvalidOperationException">
    /// Thrown if the counter value is negative.
    /// </exception>
    /// <exception cref="ArgumentException">
    /// Thrown if <paramref name="randomBytes"/> is not exactly 4 bytes long, or <paramref name="now"/> is  before unix epoch.
    /// </exception>
    /// <returns>
    /// A <see cref="Uuid"/> `v7`.
    /// </returns>
    public static Uuid FromCounterV7(
        ref int counter,
        Timestamp now,
        ReadOnlySpan<byte> randomBytes // must be length 4
    )
    {
        if (randomBytes.Length != 4)
        {
            throw new ArgumentException("randomBytes must be exactly 4 bytes", nameof(randomBytes));
        }

        if (counter < 0)
        {
            throw new InvalidOperationException("uuid counter must be non-negative");
        }

        if (now.MicrosecondsSinceUnixEpoch < 0)
        {
            throw new ArgumentException("timestamp before unix epoch", nameof(now));
        }
        var unixTsMs = now.MicrosecondsSinceUnixEpoch / 1_000;

        // monotonic 31-bit
        var counterVal = counter;
        counter = (counter + 1) & 0x7FFF_FFFF;

        Span<byte> bytes = stackalloc byte[16];

View on GitHub (pinned to 524b4487d9)

When it happens

Trigger: Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs:127 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/a0f357c2f3f9756f. Report an issue: GitHub.