Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2C02C10994 for ; Tue, 4 Feb 2014 02:33:29 +0000 (UTC) Received: (qmail 7146 invoked by uid 500); 4 Feb 2014 02:33:27 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 6730 invoked by uid 500); 4 Feb 2014 02:33:27 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 6722 invoked by uid 99); 4 Feb 2014 02:33:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Feb 2014 02:33:26 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [216.109.115.17] (HELO nm14-vm2.access.bullet.mail.bf1.yahoo.com) (216.109.115.17) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Feb 2014 02:33:17 +0000 Received: from [66.196.81.165] by nm14.access.bullet.mail.bf1.yahoo.com with NNFMP; 04 Feb 2014 02:32:55 -0000 Received: from [66.196.81.134] by tm11.access.bullet.mail.bf1.yahoo.com with NNFMP; 04 Feb 2014 02:32:55 -0000 Received: from [127.0.0.1] by omp1010.access.mail.bf1.yahoo.com with NNFMP; 04 Feb 2014 02:32:55 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 413799.7008.bm@omp1010.access.mail.bf1.yahoo.com Received: (qmail 94349 invoked by uid 60001); 4 Feb 2014 02:32:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sbcglobal.net; s=s1024; t=1391481174; bh=FISuK0003ris1S3Xvtf9TkFq9axG0/XmPU5vLgebMGI=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=rOOqIgfp+qyyUsf8jtpny0IMcmZrgaqs8E/5w5QOU4fLJs/jtNnzbOOcFnaUvg3MTKweVRYnvY+qoGSodMJShCL2C4+kcU0JEtIwto+S+3QKHvT7Pgjf5GIO3sk8hTWQcKG9bJ5ton53FUPevycbvxHOpN8ZyC04RBlEWPsrYSs= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=sbcglobal.net; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=CmfWtd00NzUfIcrF7tIOr2/8QTb0tKQz+A0Hsts1UE7tS/kpIN9DQFSVf2txtr0886JAh0qk6/ZHuHRI3HRND+nI2zPXR48Llrgp9B62bcSbSIc111nNb/3h8NdkUxVjCw9CKmVKj29XEDn3Ween4uREKU68IqVmXJpiYaiX9dc=; X-YMail-OSG: fQXvegcVM1lQNXvB3AwAEPeOp2epFyLgrF9u8yusUQ8XM7H mBdmOnbjRo7_8OHoC9LRGXI3SQ3dHg0jJ8.0ZnNdSZFgq.wXif8n7c_eNiBJ EoMMrgEp68GJOJVkIcnoJ9j68xvpx9uilmtBOjykiYe6z_usE.zLX1GmBva4 J7YpkC1Wlv8THhzFXP8Rx_7WqSg7lI0zpNEqq.H7XDd7JH5ddh4w4sifclmz J2XlNDBLNbHDzgOZaxSGGOdr6NVk6vDsVQAI7lZ8uSvX.fO2znH2kv1611Cx zftcSspWeoH.BgbVZJt_czaoOYrO8_JtFD5RdAGu93ptqmLoczai1sGN5LH8 5qP788mANeKLDIBtchqQ6XINAhWfnWYxznWfPrlJSNpfdtJ3QXQWvZBhzTlC qbBxEOLr2zsnyFH6RZNVkpDryccLS8df15vlBGtKG6ZRz7XJ0DStORu7stcI c59N.BtMa1g3lRt3iNeeCstfI5HB0V_9cDBJQBvlNu23ivWoyxChuW81svTA _NMDIhqI50sMsRGyJYwt0vR0VuATLH9Dcv4VMmbyQnekJiqBcT1K1KGrvRbJ QmH3NMFci_H4zMm1bIg.AdM6yEVKvA.oo Received: from [99.189.12.49] by web181705.mail.ne1.yahoo.com via HTTP; Mon, 03 Feb 2014 18:32:54 PST X-Rocket-MIMEInfo: 002.001,T2guwqAgTWFrZXMgc2Vuc2UuwqAgRGlkbid0IHRoaW5rIHRoYXQgaXQgd291bGQgcHJvY2VzcyBpdCdzIG93biBkb2N1bWVudC4KClRoYW5rcyEKCgoKCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCiBGcm9tOiBBbGV4YW5kZXIgU2hvcmluIDxreGVwYWxAZ21haWwuY29tPgpUbzogInVzZXJAY291Y2hkYi5hcGFjaGUub3JnIiA8dXNlckBjb3VjaGRiLmFwYWNoZS5vcmc.IApTZW50OiBNb25kYXksIEZlYnJ1YXJ5IDMsIDIwMTQgODoyOSBQTQpTdWJqZWN0OiBSZTogU0VSVkVSIEVSUk9SIG9uIGEBMAEBAQE- X-Mailer: YahooMailWebService/0.8.174.629 References: <1391475913.38078.YahooMailNeo@web181704.mail.ne1.yahoo.com> Message-ID: <1391481174.85704.YahooMailNeo@web181705.mail.ne1.yahoo.com> Date: Mon, 3 Feb 2014 18:32:54 -0800 (PST) From: Scott Weber Reply-To: Scott Weber Subject: Re: SERVER ERROR on a filter. To: "user@couchdb.apache.org" In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-237291172-524402489-1391481174=:85704" X-Virus-Checked: Checked by ClamAV on apache.org ---237291172-524402489-1391481174=:85704 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Oh.=A0 Makes sense.=A0 Didn't think that it would process it's own document= .=0A=0AThanks!=0A=0A=0A=0A=0A________________________________=0A From: Alex= ander Shorin =0ATo: "user@couchdb.apache.org" =0ASent: Monday, February 3, 2014 8:29 PM=0ASubject: Re: SER= VER ERROR on a filter.=0A =0A=0AFilter functions are processing all documen= ts, including design one.=0AThis error was raised exactly for it since it h= as no field flds and=0Aaccessing by index for undefined value raises an err= or. You should add=0Aadditional check to you filter to lookup doc.flds[1] v= alue for those=0Adocuments that hasn't it - LBYL[1] is a good practice to f= ollow to=0Aavoid unexpectable errors.=0A=0A[1]: LBYL - Look before you leap= . This coding style explicitly tests=0Afor pre-conditions before making cal= ls or lookups.=0A--=0A,,,^..^,,,=0A=0A=0AOn Tue, Feb 4, 2014 at 5:05 AM, Sc= ott Weber wrote:=0A> I am now working with filte= rs.=A0 I have created a small handful of docs.=A0 Each one consists of an a= rray of fields.=A0 A sample of one is below:=0A>=0A> {=A0 "_id": "101", "_r= ev": "1-b3303229104420834b1cf8fd22a75676", "name": "101", "flds": [ "10", "= 11", "aa", "bb" ] }=0A>=0A> And here is the filter function I am using (in = a design called "lookup"):=0A> "filters": { "getdoc": "function(doc, req) {= =0A> log(doc.flds[1]);=0A> return true;}" }=0A>=0A> I get the correct respo= nse for the URL: http://localhost:5984/db/_changes?filter=3D/lookup/getdoc,= with a code of 200.=0A> And the function *does* log "doc.flds[1]" as expec= ted.=0A>=0A> Then the log shows a server error 500, reporting that "doc.fld= s" in undefined.=A0 All occurring within one HTTP request.=0A>=0A> The full= log of the error is below (complete with line wrapping).=A0 Is something b= roken?=A0 Or am I doing something incorrect?=0A>=0A> Thanks for any advice.= =0A>=0A> -Scott=0A>=0A> [info] [<0.2067.0>] 127.0.0.1 - - GET /db/_changes?= filter=3D/lookup/getdoc 200=0A> [info] [<0.200.0>] OS Process #Port<0.5107>= Log :: 11=0A> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 12=0A> [i= nfo] [<0.200.0>] OS Process #Port<0.5107> Log :: 13=0A> [info] [<0.200.0>] = OS Process #Port<0.5107> Log :: 14=0A> [info] [<0.200.0>] OS Process #Port<= 0.5107> Log :: 15=0A> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 16= =0A> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 17=0A> [error] [<0.= 2067.0>] OS Process Error <0.200.0> :: {<<"TypeError">>,=0A> {[{<<"message"= >>,=0A> <<"doc.flds is undefined">>},=0A> {<<"fileName">>,=0A> <<"filters.g= etdoc">>},=0A> {<<"lineNumber">>,1},=0A> {<<"stack">>,=0A> <<"([object Obje= ct],[object Object])@filters.getdoc:1\n(function (doc, req) {log(doc.flds[1= ]);return true;},[object Object],[object Array])@../share/couchdb/server/ma= in.js:510\n(\"_design/lookup\",[object Array],[object Array])@../share/couc= hdb/server/main.js:1517\n()@../share/couchdb/server/main.js:1562\n@../share= /couchdb/server/main.js:1573\n">>}]}}=0A> [info] [<0.2067.0>] 127.0.0.1 - -= GET /db/_changes?filter=3D/lookup/getdoc 500=0A> [error] [<0.2067.0>] http= d 500 error response:=0A> {"error":"TypeError","reason":"{[{<<\"message\">>= ,<<\"doc.flds is undefined\">>},\n=A0 {<<\"fileName\">>,<<\"filters.getdoc\= ">>},\n=A0 {<<\"lineNumber\">>,1},\n=A0 {<<\"stack\">>,\n=A0 <<\"([object = Object],[object Object])@filters.getdoc:1\\n(function (doc, req) {log(doc.f= lds[1]);return true;},[object Object],[object Array])@../share/couchdb/serv= er/main.js:510\\n(\\\"_design/lookup\\\",[object Array],[object Array])@../= share/couchdb/server/main.js:1517\\n()@../share/couchdb/server/main.js:1562= \\n@../share/couchdb/server/main.js:1573\\n\">>}]}"} ---237291172-524402489-1391481174=:85704--