Skip to content

fix(limit-count): correct error() call in gen_limit_key#13358

Open
suryaparua-official wants to merge 2 commits into
apache:masterfrom
suryaparua-official:fix/limit-count-clean
Open

fix(limit-count): correct error() call in gen_limit_key#13358
suryaparua-official wants to merge 2 commits into
apache:masterfrom
suryaparua-official:fix/limit-count-clean

Conversation

@suryaparua-official
Copy link
Copy Markdown

Summary

Fixes #13357

Changes

In apisix/plugins/limit-count/init.lua at line 262, the error()
function was called with incorrect arguments:

-- Before (wrong)
error("failed to generate key invalid parent: ", core.json.encode(parent))

-- After (correct)
error("failed to generate key invalid parent: " .. core.json.encode(parent))

Lua's error(message, level) expects the second argument to be an
integer (stack level: 0, 1, or 2), not a string. The previous code
would cause LuaJIT to raise:

bad argument #2 to 'error' (number expected, got string)

Test

Added a test case in t/plugin/limit-count5.t to verify the error
message is correct when _meta.parent is missing.

The second argument to Lua's error(msg, level) must be an integer
(stack level), not a string. Passing core.json.encode(parent) as
the level causes LuaJIT to raise:
  bad argument apache#2 to error (number expected, got string)

Fix: concatenate the JSON into the message string using '..'.

Also add a test case to verify the error message is correct
when _meta.parent is missing.

Fixes apache#13357
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels May 12, 2026
Comment thread t/plugin/limit-count5.t
commit2: 0
peek4: 0
commit3: rejected

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need three empty lines in between tests.

@hachi029
Copy link
Copy Markdown
Contributor

A similar error occurs in apisix/discovery/dns/init.lua:81

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

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(limit-count): incorrect error() call in gen_limit_key passes string as level argument

3 participants