Page MenuHomePhabricator

Use phutil_json_encode() in AphrontResponse to raise better errors
ClosedPublic

Authored by epriestley on Aug 26 2016, 12:36 PM.
Tags
None
Referenced Files
F15385144: D16457.id.diff
Fri, Mar 14, 9:49 PM
F15384484: D16457.id39583.diff
Fri, Mar 14, 8:02 PM
Unknown Object (File)
Tue, Feb 18, 11:39 AM
Unknown Object (File)
Feb 11 2025, 7:23 PM
Unknown Object (File)
Feb 10 2025, 5:20 AM
Unknown Object (File)
Feb 9 2025, 2:08 PM
Unknown Object (File)
Feb 9 2025, 2:16 AM
Unknown Object (File)
Feb 9 2025, 2:16 AM
Subscribers
None

Details

Summary

Ref T11524. This problem was more difficult to diagnose than necessary because we swallow errors silently in AphontResponse when emitting JSON responses.

Instead of using json_encode(), use phutil_json_encode() which throws on failure.

Test Plan

Old behavior was HTTP 200 with no body.

New behavior is HTTP 500 with this message:

[2016-08-26 07:33:59] EXCEPTION: (HTTPFutureHTTPResponseStatus) [HTTP/500] Internal Server Error
Exception: Failed to JSON encode value (#5: Malformed UTF-8 characters, possibly incorrectly encoded): Dictionary value at key "result" is not valid UTF8, and cannot be JSON encoded: diff --git a/latin1.txt b/latin1.txt
new file mode 100644
index 0000000..ce6c927
--- /dev/null
+++ b/latin1.txt
@@ -0,0 +1 @@
+<�>
. at [<phutil>/src/future/http/BaseHTTPFuture.php:339]

Diff Detail

Repository
rP Phabricator
Branch
rawfile1
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 13459
Build 17302: Run Core Tests
Build 17301: arc lint + arc unit

Event Timeline

epriestley retitled this revision from to Use phutil_json_encode() in AphrontResponse to raise better errors.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: chad.
avivey added a reviewer: avivey.
This revision is now accepted and ready to land.Aug 26 2016, 1:37 PM
This revision was automatically updated to reflect the committed changes.