]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use phutil_json_decode instead of json_decode
authorJoshua Spence <josh@joshuaspence.com>
Mon, 4 May 2015 12:28:21 +0000 (22:28 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 4 May 2015 12:36:14 +0000 (22:36 +1000)
Summary: Generally, `phutil_json_decode` should be preferred over `json_decode`.

Test Plan: Eyeballed.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: aurelijus, Korvin, epriestley

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

src/lint/linter/ArcanistJSHintLinter.php
src/unit/parser/ArcanistPhpunitTestResultParser.php
src/workflow/ArcanistCallConduitWorkflow.php
src/workflow/ArcanistWorkflow.php

index 7a730db1a01ede97052bc1b7d2bd6c88b3b2fcda..292971250243ec1711d96037fc974eb1732ba738 100644 (file)
@@ -132,14 +132,14 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
   }
 
   protected function parseLinterOutput($path, $err, $stdout, $stderr) {
-    $errors = json_decode($stdout, true);
-
-    if (!is_array($errors)) {
+    $errors = null;
+    try {
+      $error = phutil_json_decode($stdout);
+    } catch (PhutilJSONParserException $ex) {
       // Something went wrong and we can't decode the output. Exit abnormally.
-      throw new RuntimeException(
-        "JSHint returned unparseable output.\n".
-        "stdout:\n\n{$stdout}".
-        "stderr:\n\n{$stderr}");
+      throw new PhutilProxyException(
+        pht('JSHint returned unparseable output.'),
+        $ex);
     }
 
     $messages = array();
index ff06a62750751f855c407bc08d9eb2dde582de44..4c3dfc7210b69244a1a41f0dd3880bb5e24f913f 100644 (file)
@@ -172,12 +172,7 @@ final class ArcanistPhpunitTestResultParser extends ArcanistTestResultParser {
 
     $json = preg_replace('/}{\s*"/', '},{"', $json);
     $json = '['.$json.']';
-    $json = json_decode($json);
-    if (!is_array($json)) {
-      throw new Exception('JSON could not be decoded');
-    }
-
-    return $json;
+    return phutil_json_decode($json);
   }
 
 }
index f451fa2b57c42d403c01a8b75ee9cbb9ec4a9a1f..c6d3a464ba8d9532c32f24ab13d59a51cc5e7468 100644 (file)
@@ -67,8 +67,9 @@ EOTEXT
         pht('Waiting for JSON parameters on stdin...'));
     }
     $params = @file_get_contents('php://stdin');
-    $params = json_decode($params, true);
-    if (!is_array($params)) {
+    try {
+      $params = phutil_json_decode($params);
+    } catch (PhutilJSONParserException $ex) {
       throw new ArcanistUsageException(
         pht('Provide method parameters on stdin as a JSON blob.'));
     }
index f982f11816056c1284ee91e53305622dcc5033ed..77b859ec1d1e61cfc7b7837c5283578e172a6864 100644 (file)
@@ -1405,7 +1405,7 @@ abstract class ArcanistWorkflow extends Phobject {
     if (!$file) {
       return array();
     }
-    return json_decode($file, true);
+    return phutil_json_decode($file);
   }