couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Markus Jelsma - Buyways B.V." <mar...@buyways.nl>
Subject Re: _show without docid returns 500 instead of 404
Date Tue, 01 Dec 2009 11:51:00 GMT
Hello Patrick, 


I agree that operating on a null as if it were a proper document should
raise an error.  But then i believe the book should not write "If the
document with id 72d43a93eb74b5f2 does not exist, the request will
result in an HTTP 404 Not Found error response." in the paragraph
previous to the one you mention, is it not?

Must i, therefore, always manually test on existance of a document as if
i were writing a map function?


Thanks for your reply.


On Tue, 2009-12-01 at 22:39 +1100, Patrick Barnes wrote:

> Hi Markus,
> 
> When you get a 500 error, it is typically because one of your javascript 
> functions has had a run-time error.
> 
> In your error log, see: "JavaScript function raised error: TypeError: 
> doc is null"
> 
> You can't assume that doc is always a document - As the book states in a 
> following paragraph, show functions can be called without any id, and 
> the show function is then called with doc being null.
> 
> -Patrick
> 
> 
> Markus Jelsma - Buyways B.V. wrote:
> > Dear list,
> > 
> > 
> > According to
> > http://books.couchdb.org/relax/design-documents/shows#Querying%20Show%
> > 20Functions i should receive an HTTP 404 Not Found response, instead i
> > get a HTTP 500 Internal Server Error. I am unsure as of yet whether i am
> > doing something wrong or if i should file a bug report for this one.
> > 
> > Here are my two documents in my test database named shows:
> > 
> > {
> >    "_id": "_design/test",
> >    "_rev": "1-21a6d69070ae4bec3e9f14fbb7f93201",
> >    "shows": {
> >        "summary": "function (doc, req) { return '<h1>'+doc.title+'</h1><p>'+doc.body+'</p>';
} "
> >    }
> > }
> > 
> > and
> > 
> > {
> > 
> >    "_id": "bd108c433aedaa1bd2def0ec85e59a0d",
> >    "_rev": "3-5a031adf97aabe4888b9bfb94ba28d13",
> >    "title": "title",
> >    "body": "body text"
> > }
> > 
> > 
> > I receive proper results using the following HTTP GET request
> > http://zealand:5984/shows/_design/test/_show/summary/bd108c433aedaa1bd2def0ec85e59a0d
> > - code : 200
> > - body : <h1>title</h1><p>body text</p>
> > 
> > Now consider querying the same show function with a non-existing
> > document id 
> > http://zealand:5984/shows/_design/test/_show/summary/404
> > - code 500
> > - body {"error":"normal","reason":"{gen_server,call,\n
> > [couch_query_servers,\n             {ret_proc,{proc,<0.1481.0>,<<
> > \"javascript\">>,\n
> > {couch_os_process,prompt},\n
> > {couch_os_process,set_timeout},\n
> > {couch_os_process,stop}}}]}"}
> > 
> > 
> > 
> > Here is the output in the couch.log file:
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [debug] [<0.1594.0>] OAuth Params: []
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [info] [<0.1726.0>] OS Process ::
> > function raised error: TypeError: doc is null
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [info] [<0.1726.0>] OS Process ::
> > stacktrace: (null,[object Object])@:0
> > runShow(function (doc, req) {return "<h1>" + doc.title + "</h1><p>"
+
> > doc.body + "</p>";},null,[object Object],"function (doc, req) { return
> > '<h1>'+doc.title+'</h1><p>'+doc.body+'</p>'; }
> > ")@/usr/share/couchdb/server/main.js:388
> > ("function (doc, req) { return '<h1>'+doc.title+'</h1><p>'+doc.body
> > +'</p>'; } ",null,[object Object])@/usr/share/couchdb/server/main.js:358
> > @/usr/share/couchdb/server/main.js:842
> > 
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [error] [<0.1594.0>] OS Process Error ::
> > {render_error,{[{<<"body">>,
> >                                      <<"<html><body><h1>Render
> > Error</h1><p>JavaScript function raised error: TypeError: doc is
> > null</p><h2>Stacktrace:</h2><code><pre>(null,[object
Object])@:0
> > \nrunShow(function (doc, req) {return \"&lt;h1&gt;\" + doc.title +
> > \"&lt;/h1&gt;&lt;p&gt;\" + doc.body + \"&lt;/p&gt;\";},null,[object
> > Object],\"function (doc, req) { return '&lt;h1&gt;'+doc.title
> > +'&lt;/h1&gt;&lt;p&gt;'+doc.body+'&lt;/p&gt;'; }
> > \")@/usr/share/couchdb/server/main.js:388\n(\"function (doc, req)
> > { return '&lt;h1&gt;'+doc.title+'&lt;/h1&gt;&lt;p&gt;'+doc.body
> > +'&lt;/p&gt;'; } \",null,[object
> > Object])@/usr/share/couchdb/server/main.js:358
> > \n@/usr/share/couchdb/server/main.js:842\n</pre></code><h2>Function
> > source:</h2><code><pre>function (doc, req) { return
> > '&lt;h1&gt;'+doc.title+'&lt;/h1&gt;&lt;p&gt;'+doc.body+'&lt;/p&gt;';
}
> > </pre></code></body></html>">>}]}}
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [debug] [<0.1628.0>] Unknown linked
> > process died: <0.1726.0> (reason: normal)
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [error] [<0.53.0>]
> > {error_report,<0.24.0>,
> >               {<0.53.0>,supervisor_report,
> >                [{supervisor,{local,couch_secondary_services}},
> >                 {errorContext,child_terminated},
> >                 {reason,normal},
> >                 {offender,[{pid,<0.1628.0>},
> >                            {name,query_servers},
> >                            {mfa,{couch_query_servers,start_link,[]}},
> >                            {restart_type,permanent},
> >                            {shutdown,brutal_kill},
> >                            {child_type,worker}]}]}}
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [error] [<0.1594.0>] Uncaught error in
> > HTTP request: {exit,
> >                                  {normal,
> >                                   {gen_server,call,
> >                                    [couch_query_servers,
> >                                     {ret_proc,
> >                                      {proc,<0.1726.0>,<<"javascript">>,
> >                                       {couch_os_process,prompt},
> >                                       {couch_os_process,set_timeout},
> >                                       {couch_os_process,stop}}}]}}}
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [info] [<0.1594.0>] Stacktrace:
> > [{gen_server,call,2},
> >              {couch_query_servers,ret_os_process,1},
> >              {couch_query_servers,render_doc_show,6},
> >              {couch_httpd_show,'-send_doc_show_response/6-fun-0-',6},
> >              {couch_httpd_db,do_db_req,2},
> >              {couch_httpd,handle_request,5},
> >              {mochiweb_http,headers,5},
> >              {proc_lib,init_p_do_apply,3}]
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [debug] [<0.1594.0>] httpd 500 error
> > response:
> >  {"error":"normal","reason":"{gen_server,call,\n
> > [couch_query_servers,\n             {ret_proc,{proc,<0.1726.0>,<<
> > \"javascript\">>,\n
> > {couch_os_process,prompt},\n
> > {couch_os_process,set_timeout},\n
> > {couch_os_process,stop}}}]}"}
> > 
> > 
> > [Tue, 01 Dec 2009 10:31:37 GMT] [info] [<0.1594.0>] 192.168.218.87 - -
> > 'GET' /shows/_design/test/_show/summary/404 50
> > 
> > 
> > 
> > I am using CouchDB 0.10.0 from Ubuntu Karmic's repository. Any
> > assistance is much appreciated.
> > 
> > 
> > Regards,
> > 
> > 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message