{"record":{"id":"ddcc407c5fc301fd","repo":"microsoft/garnet","slug":"errstr","errorCode":null,"errorMessage":"{errStr}","messagePattern":"\\{errStr\\}","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"error","filePath":"libs/server/Lua/LuaRunner.cs","lineNumber":439,"sourceCode":"        public unsafe void CompileForRunner()\n        {\n            state.ExpectLuaStackEmpty();\n\n            runnerAdapter = new RunnerAdapter(scratchBufferBuilder);\n            try\n            {\n                LuaRunnerTrampolines.SetCallbackContext(this);\n                state.PushCFunction(&LuaRunnerTrampolines.CompileForRunner);\n                var res = state.PCall(0, 0);\n                if (res == LuaStatus.OK)\n                {\n                    var resp = runnerAdapter.Response;\n                    var respStart = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(resp));\n                    var respEnd = respStart + resp.Length;\n                    if (RespReadUtils.TryReadErrorAsSpan(out var errSpan, ref respStart, respEnd))\n                    {\n                        var errStr = Encoding.UTF8.GetString(errSpan);\n                        throw new GarnetException(errStr);\n                    }\n                }\n                else\n                {\n                    throw new GarnetException($\"Internal Lua Error: {res}\");\n                }\n            }\n            finally\n            {\n                runnerAdapter = default;\n                LuaRunnerTrampolines.ClearCallbackContext(this);\n            }\n        }\n\n        /// <summary>\n        /// Compile script for a <see cref=\"RespServerSession\"/>.\n        /// \n        /// Any errors encountered are written out as Resp errors.","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Lua/LuaRunner.cs#L421-L457","documentation":"Thrown by LuaRunner.CompileForRunner after the user's script compiled under a protected call that returned OK, but the runner produced a RESP -ERROR frame in its response buffer. errStr is the decoded RESP error - typically the actual Lua compile/syntax error reported back through the runner adapter. This is the normal path for surfacing a malformed user script.","triggerScenarios":"A client runs FUNCTION LOAD (or an internal compile) with a Lua script that is syntactically invalid or rejected by the sandboxed compiler; the compile ran, the runner wrote a RESP error, and CompileForRunner rethrows it as a GarnetException carrying that error text.","commonSituations":"Typo/syntax error in a Lua function; using a disallowed Lua construct; referencing a library function that is not in the sandbox.","solutions":["Read errStr - it is the precise Lua error (often with a line number + message).","Fix the script and reload the function.","If the error references an unknown function/global, check the sandbox's allowed-function list."],"exampleFix":"-- before (Lua)\n#!lua name=bad\nredis.register_function('f', function(keys, argv) return keys[  end)\n-- after\n#!lua name=good\nredis.register_function('f', function(keys, argv) return keys[1] end)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    server.FunctionLoad(scriptSrc);\n} catch (GarnetException ex) when (IsLuaCompileError(ex.Message)) {\n    // ex.Message is the Lua error; surface to the developer, fix the script\n    return BadRequest(ex.Message);\n}","preventionTips":["Lint/luacheck scripts before deploying them to the server.","Keep function definitions small and unit-test them against a local Garnet/Redis before FUNCTION LOAD."],"tags":["lua","scripting","user-script","compile"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}