Return-Path: Delivered-To: apmail-incubator-couchdb-commits-archive@locus.apache.org Received: (qmail 28111 invoked from network); 23 Jun 2008 20:17:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Jun 2008 20:17:08 -0000 Received: (qmail 53646 invoked by uid 500); 23 Jun 2008 20:17:10 -0000 Delivered-To: apmail-incubator-couchdb-commits-archive@incubator.apache.org Received: (qmail 53625 invoked by uid 500); 23 Jun 2008 20:17:10 -0000 Mailing-List: contact couchdb-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-commits@incubator.apache.org Received: (qmail 53616 invoked by uid 99); 23 Jun 2008 20:17:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jun 2008 13:17:10 -0700 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; Mon, 23 Jun 2008 20:16:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 22F6323889C2; Mon, 23 Jun 2008 13:16:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r670732 - in /incubator/couchdb/trunk/share: server/main.js www/script/couch_tests.js Date: Mon, 23 Jun 2008 20:16:48 -0000 To: couchdb-commits@incubator.apache.org From: cmlenz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080623201648.22F6323889C2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cmlenz Date: Mon Jun 23 13:16:47 2008 New Revision: 670732 URL: http://svn.apache.org/viewvc?rev=670732&view=rev Log: Improve error handling for undefined values emitted by map functions. Closes COUCHDB-83. Modified: incubator/couchdb/trunk/share/server/main.js incubator/couchdb/trunk/share/www/script/couch_tests.js Modified: incubator/couchdb/trunk/share/server/main.js URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/server/main.js?rev=670732&r1=670731&r2=670732&view=diff ============================================================================== --- incubator/couchdb/trunk/share/server/main.js [utf-8] (original) +++ incubator/couchdb/trunk/share/server/main.js [utf-8] Mon Jun 23 13:16:47 2008 @@ -80,9 +80,7 @@ map_results = []; try { funs[i](doc); - buf.push(map_results.filter(function(pair) { - return pair[0] !== undefined && pair[1] !== undefined; - })); + buf.push(toJSON(map_results)); } catch (err) { if (err == "fatal_error") { // Only if it's a "fatal_error" do we exit. What's a fatal error? @@ -150,7 +148,7 @@ quit(); } } catch (exception) { - print(toJSON(exception.toString())); + print(toJSON(exception)); } } @@ -181,7 +179,7 @@ function toJSON(val) { if (typeof(val) == "undefined") { - throw {error:"bad_value", reason:"Cannot encode 'undefined' value as JSON"}; + throw "Cannot encode 'undefined' value as JSON"; } var subs = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'}; Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=670732&r1=670731&r2=670732&view=diff ============================================================================== --- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original) +++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Jun 23 13:16:47 2008 @@ -58,7 +58,7 @@ // create a map function that selects all documents whose "a" member // has a value of 4, and then returns the document's b value. var mapFunction = function(doc){ - if(doc.a==4) + if (doc.a==4) emit(null, doc.b); }; @@ -769,6 +769,38 @@ T(results.rows[0].value[0] == conflictRev); }, + view_errors: function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + var doc = {integer: 1, string: "1", array: [1, 2, 3]}; + T(db.save(doc).ok); + + // emitting a key value that is undefined should result in that row not + // being included in the view results + var results = db.query(function(doc) { + emit(doc.undef, null); + }); + T(results.total_rows == 0); + + // if a view function throws an exception, its results are not included in + // the view index, but the view does not itself raise an error + var results = db.query(function(doc) { + doc.undef(); // throws an error + }); + T(results.total_rows == 0); + + // if a view function includes an undefined value in the emitted key or + // value, an error is logged and the result is not included in the view + // index, and the view itself does not raise an error + var results = db.query(function(doc) { + emit([doc._id, doc.undef], null); + }); + T(results.total_rows == 0); + }, + view_pagination: function(debug) { var db = new CouchDB("test_suite_db"); db.deleteDb();