You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "nic-6443 (via GitHub)" <gi...@apache.org> on 2026/05/21 06:16:45 UTC
[PR] fix: normalize qjson errors in request json [apisix]
nic-6443 opened a new pull request, #13407:
URL: https://github.com/apache/apisix/pull/13407
This follows up on the qjson review in #13386. qjson can raise Lua errors from decode/materialize/encode paths, while the request JSON helper callers expect the same `nil, err` shape as `core.json`.
This patch wraps the qjson paths and normalizes those failures to `nil, err`, while keeping cjson and simdjson behavior unchanged. It also adds a core request test for malformed request body decode and qjson encode failures.
Checks run:
- `git diff --check`
- `luacheck apisix/core/request_json.lua`
- `perl -I. -c t/core/request.t`
- focused runtime smoke for qjson decode/encode error normalization
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: normalize qjson errors in request json [apisix]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13407:
URL: https://github.com/apache/apisix/pull/13407#discussion_r3279056586
##########
apisix/core/request_json.lua:
##########
@@ -28,6 +28,35 @@ local configured_name
local _M = {}
+local function qjson_decode(str)
+ local ok, decoded, err = pcall(qjson.decode, str)
+ if not ok then
+ return nil, tostring(decoded)
+ end
+
+ if not decoded then
+ return nil, err
+ end
+
+ ok, decoded = pcall(qjson.materialize, decoded)
+ if not ok then
+ return nil, tostring(decoded)
+ end
+
Review Comment:
`qjson_decode` wraps `qjson.materialize` with `pcall`, but it only captures the first return value. If `qjson.materialize` returns `nil, err` (non-throwing failure), this currently returns `nil` with a missing/empty error message, regressing the previous `return qjson.materialize(decoded)` behavior. Capture the second return value from `pcall(...)` and propagate it when `decoded` is falsy (similar to how `qjson.decode` is handled).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: normalize qjson errors in request json [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 merged PR #13407:
URL: https://github.com/apache/apisix/pull/13407
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: normalize qjson errors in request json [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #13407:
URL: https://github.com/apache/apisix/pull/13407#discussion_r3279073409
##########
apisix/core/request_json.lua:
##########
@@ -28,6 +28,35 @@ local configured_name
local _M = {}
+local function qjson_decode(str)
+ local ok, decoded, err = pcall(qjson.decode, str)
+ if not ok then
+ return nil, tostring(decoded)
+ end
+
+ if not decoded then
+ return nil, err
+ end
+
+ ok, decoded = pcall(qjson.materialize, decoded)
+ if not ok then
+ return nil, tostring(decoded)
+ end
+
Review Comment:
Good catch. Updated the qjson materialize wrapper to preserve the non-throwing `nil, err` return path, and localized the built-ins used by the wrapper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org