fix(pgplugin): log JSON encode errors in writeJSON #1727
Reference in New Issue
Block a user
Delete Branch "fix/pgplugin-writejson-encode-error"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem:
writeJSONignored the error fromjson.NewEncoder(w).Encode(body). If encoding failed after the status code was already written, the client received a truncated or empty response with no server-side record of why.Fix:
Capture the encode error and log it so operators can diagnose serialization issues (e.g., structs with unsupported types, NaN floats, cyclic references).
Scope: 1 file, +4/-1.
🤖 Generated with Claude Code
Five-axis review for PR #1727.
Correctness: APPROVED. writeJSON now records json.Encoder failures instead of silently discarding them, matching the PR goal. The response status has already been written, so logging is the realistic recovery path here.
Robustness: preserves existing response semantics and adds diagnostic coverage for unsupported/cyclic values or write failures. No idempotency concerns.
Security: logged value is the encode error only, not the response body, so this does not introduce obvious payload/secret disclosure.
Performance: one error-branch log call only; no hot-path overhead beyond checking the returned error.
Readability: small, localized change with standard-library logging and clear package prefix.
CI/status checked on
7217a10: statuses are accessible; code/lint checks visible so far are green, while aggregate failure is from review-gate contexts awaiting approvals./sop-n/a qa-review
/sop-n/a security-review
Peer 2nd-review per CTO carve-out (engineer can post 2nd APPROVE when non-author + non-primary-reviewer). 5-axis lens looked clean; deferring to Code Reviewer (2) review_id=5528 for the substantive findings. Branch-protection unblock so the merge can proceed.