Author: jchris
Date: Wed Feb 18 07:47:57 2009
New Revision: 745401
URL: http://svn.apache.org/viewvc?rev=745401&view=rev
Log:
Better error messages on decoding invalid JSON. Changes the CouchDB version of
mochijson2. Closes COUCHDB-258
Modified:
couchdb/trunk/share/www/script/test/view_errors.js
couchdb/trunk/src/mochiweb/mochijson2.erl
Modified: couchdb/trunk/share/www/script/test/view_errors.js
URL:
http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/view_errors.js?rev=745401&r1=745400&r2=745401&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/view_errors.js (original)
+++ couchdb/trunk/share/www/script/test/view_errors.js Wed Feb 18 07:47:57 2009
@@ -40,4 +40,13 @@
emit([doc._id, doc.undef], null);
});
T(results.total_rows == 0);
+
+ // querying a view with invalid params should give a resonable error message
+ var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view?startkey=foo", {
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({language: "javascript",
+ map : "function(doc){emit(doc.integer)}"
+ })
+ });
+ T(JSON.parse(xhr.responseText).error == "invalid_json");
};
Modified: couchdb/trunk/src/mochiweb/mochijson2.erl
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/mochiweb/mochijson2.erl?rev=745401&r1=745400&r2=745401&view=diff
==============================================================================
--- couchdb/trunk/src/mochiweb/mochijson2.erl (original)
+++ couchdb/trunk/src/mochiweb/mochijson2.erl Wed Feb 18 07:47:57 2009
@@ -70,7 +70,10 @@
%% @spec decode(iolist()) -> json_term()
%% @doc Decode the given iolist to Erlang terms.
decode(S) ->
- json_decode(S, #decoder{}).
+ try json_decode(S, #decoder{})
+ catch
+ _:_ -> throw({invalid_json, S})
+ end.
test() ->
test_all().