Skip to content

Fix(router): handle debug.getinfo returning nil for non-Lua functions#4

Open
PlumBlossomMaid wants to merge 1 commit intoTRIGONIM:mainfrom
PlumBlossomMaid:fix/layer-debug-getinfo-nil-check
Open

Fix(router): handle debug.getinfo returning nil for non-Lua functions#4
PlumBlossomMaid wants to merge 1 commit intoTRIGONIM:mainfrom
PlumBlossomMaid:fix/layer-debug-getinfo-nil-check

Conversation

@PlumBlossomMaid
Copy link
Copy Markdown

Issue

debug.getinfo(fn, "Su") behaves differently depending on the function type:

  • For pure Lua functions: returns a table with nparams field
  • For C functions or wrapped callbacks: may return nil or a table without nparams

This inconsistency causes attempt to compare number with nil errors in layer.lua:57 and layer.lua:47 on Windows/Lua 5.1 environments.

Root Cause

The pegasus HTTP server passes some C-level callbacks and wrapped functions through the middleware chain. When these reach the layer handlers, debug.getinfo fails to extract parameter count information.

Fix

Added defensive checks before accessing nparams:

Before:

if debug.getinfo(fn, "Su").nparams > 3 then

After:

local info = debug.getinfo(fn, "Su")
if not info or not info.nparams or info.nparams > 3 then

Affected Functions

  • LAYER_MT:handle_request
  • LAYER_MT:handle_error

Environment

  • OS: Windows 10
  • Lua: 5.1.5
  • Dependencies: pegasus 1.1.0, copas 4.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant