{"record":{"id":"9dc23dac9c056cf7","repo":"tursodatabase/turso","slug":"segment-size-must-be-positive","errorCode":null,"errorMessage":"Segment size must be positive.","messagePattern":"Segment size must be positive\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoSyncDatabaseOptions.cs","lineNumber":93,"sourceCode":"{\n    public int? PrefixLength { get; init; }\n    public string? Query { get; init; }\n    public long? SegmentSize { get; init; }\n    public bool Prefetch { get; init; }\n\n    internal void Validate()\n    {\n        if (Query is not null)\n            ArgumentException.ThrowIfNullOrWhiteSpace(Query);\n\n        var hasPrefix = PrefixLength.HasValue;\n        var hasQuery = Query is not null;\n        if (hasPrefix == hasQuery)\n            throw new InvalidOperationException(\"Partial sync requires exactly one prefix or query bootstrap strategy.\");\n        if (PrefixLength is <= 0)\n            throw new ArgumentOutOfRangeException(nameof(PrefixLength), PrefixLength, \"Prefix length must be positive.\");\n        if (SegmentSize is <= 0)\n            throw new ArgumentOutOfRangeException(nameof(SegmentSize), SegmentSize, \"Segment size must be positive.\");\n        if (SegmentSize is { } segmentSize && (ulong)segmentSize > nuint.MaxValue)\n            throw new ArgumentOutOfRangeException(nameof(SegmentSize), SegmentSize, \"Segment size exceeds the native platform size.\");\n    }\n}\n\npublic sealed class TursoSyncDatabaseOptions\n{\n    public TursoSyncDatabaseOptions(string path, Uri remoteUri)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(path);\n        ArgumentNullException.ThrowIfNull(remoteUri);\n        Path = path;\n        RemoteUri = remoteUri;\n    }\n\n    public string Path { get; }\n    public Uri RemoteUri { get; }\n    public string? AuthToken { get; init; }","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/bindings/dotnet/src/Turso.Data/TursoSyncDatabaseOptions.cs#L75-L111","documentation":"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.","triggerScenarios":"Creating TursoPartialSyncOptions with SegmentSize = 0 or negative (e.g. leaving an unset-by-default value explicitly assigned 0 from config).","commonSituations":"Config parsing that maps missing settings to 0 rather than null; passing an average-size calculation that returned 0 for an empty dataset.","solutions":["Set SegmentSize to a positive value, or leave it null to use the library default","Fix config binding so absent values stay null instead of becoming 0","Clamp computed values: Math.Max(1, size)"],"exampleFix":"// before\nvar partial = new TursoPartialSyncOptions { PrefixLength = 4096, SegmentSize = 0 };\n// after\nvar partial = new TursoPartialSyncOptions { PrefixLength = 4096 }; // use default segment size","handlingStrategy":"validation","validationCode":"// before constructing options:\nif (segmentSize is <= 0)\n    throw new ArgumentOutOfRangeException(nameof(segmentSize), segmentSize, \"Segment size must be positive.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var db = new TursoSyncDatabase(options);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"SegmentSize\")\n{\n    logger.LogError(ex, \"Partial sync SegmentSize must be a positive number; omit it to use the default.\");\n    throw;\n}","preventionTips":["Leave SegmentSize null unless you have a specific chunking requirement","Fix config binding so missing settings remain null rather than defaulting to 0","Clamp computed segment sizes: Math.Max(1, size)"],"tags":["dotnet","configuration","partial-sync","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-31T11:17:35.598Z","contentChangedAt":"2026-08-31T11:17:35.598Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}