{"record":{"id":"8bbdb439ddd07277","repo":"microsoft/garnet","slug":"ri-get-invalid-arguments","errorCode":null,"errorMessage":"RI.GET: invalid arguments.","messagePattern":"RI\\.GET: invalid arguments\\.","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"error","filePath":"libs/server/Storage/Session/MainStore/RangeIndexOps.cs","lineNumber":315,"sourceCode":"                var bufLen = output.SpanByteAndMemory.Length;\n                var maxValueSize = (int)stub.MaxRecordSize;\n\n                const int optimisticHeaderSize = 1 + 1 + 2; // $N\\r\\n\n                const int trailerSize = 2; // \\r\\n\n                const int maxHeaderSize = 1 + 10 + 2; // $<maxDigits>\\r\\n\n                var minBufferNeeded = maxHeaderSize + maxValueSize + trailerSize; // $<maxDigits>\\r\\n + value + \\r\\n\n\n                if (bufLen >= minBufferNeeded)\n                {\n                    // Read BfTree value directly into output buffer past the header reservation\n                    var bufStart = output.SpanByteAndMemory.SpanByte.ToPointer();\n                    var valueStart = bufStart + optimisticHeaderSize;\n                    var readResult = BfTreeService.ReadByPtrInto(stub.TreeHandle, field, valueStart, maxValueSize, out var bytesWritten);\n\n                    if (readResult == BfTreeReadResult.InvalidArguments)\n                    {\n                        logger?.LogError(\"RI.GET: invalid arguments for a {fieldLen}-byte field.\", field.Length);\n                        throw new GarnetException(\"RI.GET: invalid arguments.\");\n                    }\n\n                    if (readResult != BfTreeReadResult.Found || bytesWritten < 0)\n                    {\n                        result = RangeIndexResult.NotFound;\n                        return GarnetStatus.OK;\n                    }\n\n                    // Backfill exact header, append trailer, shift to eliminate gap\n                    var numLength = NumUtils.CountDigits(bytesWritten);\n                    var actualHeaderSize = 1 + numLength + 2; // $N\\r\\n\n                    var actualValueStart = bufStart + actualHeaderSize;\n                    if (valueStart != actualValueStart)\n                        Buffer.MemoryCopy(valueStart, actualValueStart, bytesWritten, bytesWritten);\n\n                    var tmp = bufStart;\n                    *tmp++ = (byte)'$';\n                    NumUtils.WriteInt32(bytesWritten, numLength, ref tmp);","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Storage/Session/MainStore/RangeIndexOps.cs#L297-L333","documentation":"RI.GET (RangeIndex GET) throws when the BfTree read into the output buffer returns InvalidArguments. This is the first of two RI.GET error paths — the direct SpanByte buffer path. It indicates the field span passed to the native read was structurally invalid (empty/null) or the tree handle was in a bad state.","triggerScenarios":"Calling the RI.GET operation when BfTreeService.ReadByPtrInto returns BfTreeReadResult.InvalidArguments on the direct buffer path (output.SpanByteAndMemory has a SpanByte backing). Occurs with an empty field, or a corrupted tree handle.","commonSituations":"Client sending RI.GET with an empty field name; argument parsing bug producing zero-length span; corrupted range index after crash.","solutions":["Ensure the field argument to RI.GET is non-empty.","If the error persists with a valid field, recreate the range index to rule out corruption.","Check server logs for the logged field length to confirm what was passed."],"exampleFix":"// before\nRI.GET myindex \"\"\n\n// after\nRI.GET myindex \"field1\"","handlingStrategy":"validation","validationCode":"if (field == null || field.Length == 0)\n    throw new ArgumentException(\"RI.GET field must be non-empty.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate field is non-empty before calling RI.GET.","Ensure the range index tree is initialized before any read operations.","Log field length in error handlers for diagnostics."],"tags":["range-index","bftree","ri-get","runtime","garnet"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}