better error message in check_type(), tell the types by name instead of by number
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Wed, 10 Feb 2010 19:46:04 +0000 (19:46 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Wed, 10 Feb 2010 19:46:04 +0000 (19:46 +0000)
json/json_spirit_value.h

index e8be355..e9bcd36 100644 (file)
@@ -24,6 +24,7 @@
 namespace json_spirit\r
 {\r
     enum Value_type{ obj_type, array_type, str_type, bool_type, int_type, real_type, null_type };\r
+    static const char* Value_type_name[]={"obj", "array", "str", "bool", "int", "real", "null"};\r
 \r
     template< class Config >    // Config determines whether the value uses std::string or std::wstring and\r
                                 // whether JSON Objects are represented as vectors or maps\r
@@ -341,7 +342,8 @@ namespace json_spirit
         {\r
             std::ostringstream os;\r
 \r
-            os << "value type is " << type() << " not " << vtype;\r
+            /// satoshi: tell the types by name instead of by number\r
+            os << "value is type " << Value_type_name[type()] << ", expected " << Value_type_name[vtype];\r
 \r
             throw std::runtime_error( os.str() );\r
         }\r