aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-01 16:26:44 +0930
committerMark Pulford <mark@kyne.com.au>2011-05-01 16:26:44 +0930
commitbc94292b70be41cecd2bd151b1fffcfa59480118 (patch)
tree54cf200b1d226127ab66a7590f4bb4cf0132fc2a
parentfb5405eacede2f357fe496de54830ffff06e14d3 (diff)
downloadlua-cjson-bc94292b70be41cecd2bd151b1fffcfa59480118.tar.gz
lua-cjson-bc94292b70be41cecd2bd151b1fffcfa59480118.tar.bz2
lua-cjson-bc94292b70be41cecd2bd151b1fffcfa59480118.zip
Improve encoding exception error format
Was: Cannot serialise <location>: <type> Now: Cannot serialise <type>: <reason>
-rw-r--r--lua_cjson.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index 24b9704..e5e7d1c 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -209,13 +209,13 @@ static void json_create_config(lua_State *l)
209 209
210/* ===== ENCODING ===== */ 210/* ===== ENCODING ===== */
211 211
212static void json_encode_type_exception(lua_State *l, strbuf_t *json, 212static void json_encode_exception(lua_State *l, strbuf_t *json, int lindex,
213 char *location, int lindex) 213 const char *reason)
214{ 214{
215 strbuf_free(json); 215 strbuf_free(json);
216 216
217 luaL_error(l, "Cannot serialise %s: %s", location, 217 luaL_error(l, "Cannot serialise %s: %s",
218 lua_typename(l, lua_type(l, lindex))); 218 lua_typename(l, lua_type(l, lindex)), reason);
219} 219}
220 220
221/* JSON escape a character if required, or return NULL */ 221/* JSON escape a character if required, or return NULL */
@@ -388,7 +388,8 @@ static void json_append_object(lua_State *l, json_config_t *cfg,
388 json_append_string(l, json, -2); 388 json_append_string(l, json, -2);
389 strbuf_append_string(json, ": "); 389 strbuf_append_string(json, ": ");
390 } else { 390 } else {
391 json_encode_type_exception(l, json, "table key", -2); 391 json_encode_exception(l, json, -2,
392 "table key must be a number or string");
392 /* never returns */ 393 /* never returns */
393 } 394 }
394 395
@@ -439,7 +440,7 @@ static void json_append_data(lua_State *l, json_config_t *cfg, strbuf_t *json)
439 default: 440 default:
440 /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, 441 /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD,
441 * and LUA_TLIGHTUSERDATA) cannot be serialised */ 442 * and LUA_TLIGHTUSERDATA) cannot be serialised */
442 json_encode_type_exception(l, json, "value", -1); 443 json_encode_exception(l, json, -1, "type not supported");
443 /* never returns */ 444 /* never returns */
444 } 445 }
445} 446}