This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new cee703ba84 ARROW-18144: [C++] Improve JSONTypeError error message in 
testing (#14486)
cee703ba84 is described below

commit cee703ba84883444c9bad940531f49d1a52e156c
Author: Jin Shang <[email protected]>
AuthorDate: Tue Oct 25 15:43:42 2022 +0800

    ARROW-18144: [C++] Improve JSONTypeError error message in testing (#14486)
    
    If there is a type error, ArrayFromJSON returns an error message like
    ```Invalid: Expected unsigned int or null, got JSON type 4```
    where JSON type 4 is a value of type rapidjson::Type enum. It is better to 
print type names rather than enum values such as
    ```Invalid: Expected unsigned int or null, got JSON type array```
    
    Lead-authored-by: Jin Shang <[email protected]>
    Co-authored-by: Antoine Pitrou <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/arrow/ipc/json_simple.cc | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/cpp/src/arrow/ipc/json_simple.cc b/cpp/src/arrow/ipc/json_simple.cc
index 1b93aeb2f2..eea0c97302 100644
--- a/cpp/src/arrow/ipc/json_simple.cc
+++ b/cpp/src/arrow/ipc/json_simple.cc
@@ -64,9 +64,30 @@ namespace {
 
 constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | 
rj::kParseNanAndInfFlag;
 
+const char* JsonTypeName(rj::Type json_type) {
+  switch (json_type) {
+    case rapidjson::kNullType:
+      return "null";
+    case rapidjson::kFalseType:
+      return "false";
+    case rapidjson::kTrueType:
+      return "true";
+    case rapidjson::kObjectType:
+      return "object";
+    case rapidjson::kArrayType:
+      return "array";
+    case rapidjson::kStringType:
+      return "string";
+    case rapidjson::kNumberType:
+      return "number";
+    default:
+      return "unknown";
+  }
+}
+
 Status JSONTypeError(const char* expected_type, rj::Type json_type) {
   return Status::Invalid("Expected ", expected_type, " or null, got JSON type 
",
-                         json_type);
+                         JsonTypeName(json_type));
 }
 
 class Converter {

Reply via email to