{"record":{"id":"69eb4419627c652d","repo":"microsoft/garnet","slug":"internal-lua-error-res","errorCode":null,"errorMessage":"Internal Lua Error: {res}","messagePattern":"Internal Lua Error: (.+?)","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"error","filePath":"libs/server/Lua/LuaRunner.cs","lineNumber":444,"sourceCode":"            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.\n        /// </summary>\n        public unsafe bool CompileForSession(RespServerSession session)\n        {\n            state.ExpectLuaStackEmpty();\n","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Lua/LuaRunner.cs#L426-L462","documentation":"Thrown by CompileForRunner when the protected compile call returned a non-OK LuaStatus (res) and the runner produced no RESP error frame. Unlike the RESP-error case, there is no friendly text - only the raw LuaStatus enum value. This indicates the Lua VM itself misbehaved during compilation rather than reporting a normal script error.","triggerScenarios":"state.PCall for compilation returns a non-OK status and the runner adapter's response buffer did not contain a parseable RESP error, so the code falls to the else branch and throws 'Internal Lua Error: {res}'.","commonSituations":"Out-of-memory inside the Lua VM; stack overflow; a corrupted Lua state; a build mismatch. Rare under normal load.","solutions":["Inspect the LuaStatus value (res) in the logs to map it to a Lua error class (e.g., ERRMEM, ERRERR).","Check memory pressure and configured memory limits on the Lua/runner.","Recreate the Lua state / restart the session; if reproducible, file it as an internal bug with the script that triggered it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (GarnetException ex) when (ex.Message.StartsWith(\"Internal Lua Error\")) {\n    logger.LogError(\"Lua PCall returned non-OK status during compile: {Msg}\", ex.Message);\n    throw; // typically non-recoverable for this state; report and restart session\n}","preventionTips":["Monitor memory and Lua stack usage on the server.","Capture the LuaStatus value when this fires - it is the only diagnostic available."],"tags":["lua","scripting","internal","diagnostics"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}