microsoft/garnet · error · GarnetException

{errStr}

Error message

{errStr}

What it means

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.

Source

Thrown at libs/server/Lua/LuaRunner.cs:439

        public unsafe void CompileForRunner()
        {
            state.ExpectLuaStackEmpty();

            runnerAdapter = new RunnerAdapter(scratchBufferBuilder);
            try
            {
                LuaRunnerTrampolines.SetCallbackContext(this);
                state.PushCFunction(&LuaRunnerTrampolines.CompileForRunner);
                var res = state.PCall(0, 0);
                if (res == LuaStatus.OK)
                {
                    var resp = runnerAdapter.Response;
                    var respStart = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(resp));
                    var respEnd = respStart + resp.Length;
                    if (RespReadUtils.TryReadErrorAsSpan(out var errSpan, ref respStart, respEnd))
                    {
                        var errStr = Encoding.UTF8.GetString(errSpan);
                        throw new GarnetException(errStr);
                    }
                }
                else
                {
                    throw new GarnetException($"Internal Lua Error: {res}");
                }
            }
            finally
            {
                runnerAdapter = default;
                LuaRunnerTrampolines.ClearCallbackContext(this);
            }
        }

        /// <summary>
        /// Compile script for a <see cref="RespServerSession"/>.
        /// 
        /// Any errors encountered are written out as Resp errors.

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Read errStr - it is the precise Lua error (often with a line number + message).
  2. Fix the script and reload the function.
  3. If the error references an unknown function/global, check the sandbox's allowed-function list.

Example fix

-- before (Lua)
#!lua name=bad
redis.register_function('f', function(keys, argv) return keys[  end)
-- after
#!lua name=good
redis.register_function('f', function(keys, argv) return keys[1] end)
Defensive patterns

Strategy: try-catch

Try / catch

try {
    server.FunctionLoad(scriptSrc);
} catch (GarnetException ex) when (IsLuaCompileError(ex.Message)) {
    // ex.Message is the Lua error; surface to the developer, fix the script
    return BadRequest(ex.Message);
}

Prevention

When it happens

Trigger: 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.

Common situations: Typo/syntax error in a Lua function; using a disallowed Lua construct; referencing a library function that is not in the sandbox.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/ddcc407c5fc301fd. Report an issue: GitHub.