From commits-return-1838-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Wed Feb 18 07:48:19 2009 Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 4022 invoked from network); 18 Feb 2009 07:48:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Feb 2009 07:48:19 -0000 Received: (qmail 44074 invoked by uid 500); 18 Feb 2009 07:48:19 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 44051 invoked by uid 500); 18 Feb 2009 07:48:19 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 44040 invoked by uid 99); 18 Feb 2009 07:48:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Feb 2009 23:48:19 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2009 07:48:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0652323888F4; Wed, 18 Feb 2009 07:47:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r745401 - in /couchdb/trunk: share/www/script/test/view_errors.js src/mochiweb/mochijson2.erl Date: Wed, 18 Feb 2009 07:47:57 -0000 To: commits@couchdb.apache.org From: jchris@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090218074758.0652323888F4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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().