couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Weber <scotty2...@sbcglobal.net>
Subject Re: SERVER ERROR on a filter.
Date Tue, 04 Feb 2014 02:32:54 GMT
Oh.  Makes sense.  Didn't think that it would process it's own document.

Thanks!




________________________________
 From: Alexander Shorin <kxepal@gmail.com>
To: "user@couchdb.apache.org" <user@couchdb.apache.org> 
Sent: Monday, February 3, 2014 8:29 PM
Subject: Re: SERVER ERROR on a filter.
 

Filter functions are processing all documents, including design one.
This error was raised exactly for it since it has no field flds and
accessing by index for undefined value raises an error. You should add
additional check to you filter to lookup doc.flds[1] value for those
documents that hasn't it - LBYL[1] is a good practice to follow to
avoid unexpectable errors.

[1]: LBYL - Look before you leap. This coding style explicitly tests
for pre-conditions before making calls or lookups.
--
,,,^..^,,,


On Tue, Feb 4, 2014 at 5:05 AM, Scott Weber <scotty2541@sbcglobal.net> wrote:
> I am now working with filters.  I have created a small handful of docs.  Each one consists
of an array of fields.  A sample of one is below:
>
> {  "_id": "101", "_rev": "1-b3303229104420834b1cf8fd22a75676", "name": "101", "flds":
[ "10", "11", "aa", "bb" ] }
>
> And here is the filter function I am using (in a design called "lookup"):
> "filters": { "getdoc": "function(doc, req) {
> log(doc.flds[1]);
> return true;}" }
>
> I get the correct response for the URL: http://localhost:5984/db/_changes?filter=/lookup/getdoc,
with a code of 200.
> And the function *does* log "doc.flds[1]" as expected.
>
> Then the log shows a server error 500, reporting that "doc.flds" in undefined.  All
occurring within one HTTP request.
>
> The full log of the error is below (complete with line wrapping).  Is something broken? 
Or am I doing something incorrect?
>
> Thanks for any advice.
>
> -Scott
>
> [info] [<0.2067.0>] 127.0.0.1 - - GET /db/_changes?filter=/lookup/getdoc 200
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 11
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 12
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 13
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 14
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 15
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 16
> [info] [<0.200.0>] OS Process #Port<0.5107> Log :: 17
> [error] [<0.2067.0>] OS Process Error <0.200.0> :: {<<"TypeError">>,
> {[{<<"message">>,
> <<"doc.flds is undefined">>},
> {<<"fileName">>,
> <<"filters.getdoc">>},
> {<<"lineNumber">>,1},
> {<<"stack">>,
> <<"([object Object],[object Object])@filters.getdoc:1\n(function (doc, req) {log(doc.flds[1]);return
true;},[object Object],[object Array])@../share/couchdb/server/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">>}]}}
> [info] [<0.2067.0>] 127.0.0.1 - - GET /db/_changes?filter=/lookup/getdoc 500
> [error] [<0.2067.0>] httpd 500 error response:
> {"error":"TypeError","reason":"{[{<<\"message\">>,<<\"doc.flds is undefined\">>},\n 
{<<\"fileName\">>,<<\"filters.getdoc\">>},\n  {<<\"lineNumber\">>,1},\n 
{<<\"stack\">>,\n   <<\"([object Object],[object Object])@filters.getdoc:1\\n(function
(doc, req) {log(doc.flds[1]);return true;},[object Object],[object Array])@../share/couchdb/server/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\">>}]}"}
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message