tursodatabase/turso · error · ArgumentOutOfRangeException

Segment size must be positive.

Error message

Segment size must be positive.

What it means

SegmentSize, when specified for partial sync, must be strictly positive. Validate throws ArgumentOutOfRangeException otherwise. Segment size controls chunking of the partial sync transfer, and zero (or negative) would divide transfers into impossible segments.

Source

Thrown at bindings/dotnet/src/Turso.Data/TursoSyncDatabaseOptions.cs:93

{
    public int? PrefixLength { get; init; }
    public string? Query { get; init; }
    public long? SegmentSize { get; init; }
    public bool Prefetch { get; init; }

    internal void Validate()
    {
        if (Query is not null)
            ArgumentException.ThrowIfNullOrWhiteSpace(Query);

        var hasPrefix = PrefixLength.HasValue;
        var hasQuery = Query is not null;
        if (hasPrefix == hasQuery)
            throw new InvalidOperationException("Partial sync requires exactly one prefix or query bootstrap strategy.");
        if (PrefixLength is <= 0)
            throw new ArgumentOutOfRangeException(nameof(PrefixLength), PrefixLength, "Prefix length must be positive.");
        if (SegmentSize is <= 0)
            throw new ArgumentOutOfRangeException(nameof(SegmentSize), SegmentSize, "Segment size must be positive.");
        if (SegmentSize is { } segmentSize && (ulong)segmentSize > nuint.MaxValue)
            throw new ArgumentOutOfRangeException(nameof(SegmentSize), SegmentSize, "Segment size exceeds the native platform size.");
    }
}

public sealed class TursoSyncDatabaseOptions
{
    public TursoSyncDatabaseOptions(string path, Uri remoteUri)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(path);
        ArgumentNullException.ThrowIfNull(remoteUri);
        Path = path;
        RemoteUri = remoteUri;
    }

    public string Path { get; }
    public Uri RemoteUri { get; }
    public string? AuthToken { get; init; }

View on GitHub (pinned to c1e5928725)

Solutions

  1. Set SegmentSize to a positive value, or leave it null to use the library default
  2. Fix config binding so absent values stay null instead of becoming 0
  3. Clamp computed values: Math.Max(1, size)

Example fix

// before
var partial = new TursoPartialSyncOptions { PrefixLength = 4096, SegmentSize = 0 };
// after
var partial = new TursoPartialSyncOptions { PrefixLength = 4096 }; // use default segment size
Defensive patterns

Strategy: validation

Validate before calling

// before constructing options:
if (segmentSize is <= 0)
    throw new ArgumentOutOfRangeException(nameof(segmentSize), segmentSize, "Segment size must be positive.");

Try / catch

try
{
    var db = new TursoSyncDatabase(options);
}
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "SegmentSize")
{
    logger.LogError(ex, "Partial sync SegmentSize must be a positive number; omit it to use the default.");
    throw;
}

Prevention

When it happens

Trigger: Creating TursoPartialSyncOptions with SegmentSize = 0 or negative (e.g. leaving an unset-by-default value explicitly assigned 0 from config).

Common situations: Config parsing that maps missing settings to 0 rather than null; passing an average-size calculation that returned 0 for an empty dataset.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of tursodatabase/turso@c1e5928725 (2026-08-31). Data as JSON: /api/errors/9dc23dac9c056cf7. Report an issue: GitHub.