Homec4science

Use phutil_json_encode() in AphrontResponse to raise better errors

Authored by epriestley <git@epriestley.com> on Aug 26 2016, 14:34.

Description

Use phutil_json_encode() in AphrontResponse to raise better errors

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 &quot;result&quot; 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 @@
+&lt;�&gt;
. at [<phutil>/src/future/http/BaseHTTPFuture.php:339]

Reviewers: chad, avivey

Reviewed By: avivey

Maniphest Tasks: T11524

Differential Revision: https://secure.phabricator.com/D16457

Details

Committed
epriestley <git@epriestley.com>Aug 26 2016, 16:39
Pushed
aubortJan 31 2017, 17:16
Parents
rPHd952dd591266: When importing Git repositories, treat out-of-range timestamps as the current…
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPH90294713e850: Use phutil_json_encode() in AphrontResponse to raise better errors (authored by epriestley <git@epriestley.com>).Aug 26 2016, 16:39