{"record":{"id":"310b6900a5292e4a","repo":"tursodatabase/turso","slug":"prefix-length-must-be-positive","errorCode":null,"errorMessage":"Prefix length must be positive.","messagePattern":"Prefix length must be positive\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoSyncDatabaseOptions.cs","lineNumber":91,"sourceCode":"\npublic sealed class TursoPartialSyncOptions\n{\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; }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/bindings/dotnet/src/Turso.Data/TursoSyncDatabaseOptions.cs#L73-L109","documentation":"When Validate processes a prefix bootstrap (PrefixLength is set), it requires a strictly positive value via ArgumentOutOfRangeException. A PrefixLength of zero or negative is meaningless as a bootstrap size and is rejected.","triggerScenarios":"Creating TursoPartialSyncOptions with PrefixLength = 0 or a negative value while Query is null (so the prefix strategy is selected).","commonSituations":"Computing the prefix size from a variable that defaults to 0; int/long underflow; config files with an empty value coerced to 0.","solutions":["Set PrefixLength to a positive value greater than 0","If you don't know a good size, drop PrefixLength and use a Query bootstrap instead","Guard the computed value before constructing options (Math.Max(1, computedSize))"],"exampleFix":"// before\nvar partial = new TursoPartialSyncOptions { PrefixLength = 0 };\n// after\nvar partial = new TursoPartialSyncOptions { PrefixLength = 4096 };","handlingStrategy":"validation","validationCode":"// before constructing options:\nif (prefixLength is <= 0)\n    throw new ArgumentOutOfRangeException(nameof(prefixLength), prefixLength, \"Prefix length must be positive.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var db = new TursoSyncDatabase(options);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"PrefixLength\")\n{\n    logger.LogError(ex, \"Partial sync PrefixLength must be a positive number.\");\n    throw;\n}","preventionTips":["Default computed prefix sizes to a sane minimum (Math.Max(1, computed))","Ensure config binding treats absent values as null, not 0","Sanity-check any value derived from dataset statistics before use"],"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"}