Skip to content

fix: normalize qjson errors in request json#13407

Merged
nic-6443 merged 5 commits into
apache:masterfrom
nic-6443:fix-qjson-error-normalization-20260521
May 21, 2026
Merged

fix: normalize qjson errors in request json#13407
nic-6443 merged 5 commits into
apache:masterfrom
nic-6443:fix-qjson-error-normalization-20260521

Conversation

@nic-6443
Copy link
Copy Markdown
Member

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

Copilot AI review requested due to automatic review settings May 21, 2026 06:16
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels May 21, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR normalizes qjson failures in apisix.core.request_json so callers consistently receive nil, err instead of uncaught Lua errors, aligning qjson behavior with expectations established by core.json-style helpers.

Changes:

  • Wrap qjson.decode, qjson.materialize, and qjson.encode with pcall and convert thrown errors into nil, err returns.
  • Add a t/core/request.t test to assert malformed JSON request bodies and qjson encode/decode failures return nil, err without emitting [error] logs.
  • Renumber subsequent request tests to account for the new coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apisix/core/request_json.lua Adds guarded qjson decode/materialize/encode helpers to normalize thrown errors into nil, err.
t/core/request.t Adds regression test coverage for qjson decode/encode error normalization and malformed JSON request body handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/core/request_json.lua Outdated
@nic-6443 nic-6443 requested a review from membphis May 21, 2026 07:24
@nic-6443 nic-6443 merged commit ed5ca9e into apache:master May 21, 2026
19 checks passed
@nic-6443 nic-6443 deleted the fix-qjson-error-normalization-20260521 branch May 21, 2026 08:03
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.

5 participants