Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 72304 invoked from network); 14 Dec 2009 17:33:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Dec 2009 17:33:42 -0000 Received: (qmail 73705 invoked by uid 500); 14 Dec 2009 17:33:41 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 73595 invoked by uid 500); 14 Dec 2009 17:33:41 -0000 Mailing-List: contact dev-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 dev@couchdb.apache.org Received: (qmail 73585 invoked by uid 99); 14 Dec 2009 17:33:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 17:33:40 +0000 X-ASF-Spam-Status: No, hits=-10.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 17:33:38 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5177E234C498 for ; Mon, 14 Dec 2009 09:33:18 -0800 (PST) Message-ID: <1652218406.1260811998319.JavaMail.jira@brutus> Date: Mon, 14 Dec 2009 17:33:18 +0000 (UTC) From: "Jason Davies (JIRA)" To: dev@couchdb.apache.org Subject: [jira] Commented: (COUCHDB-598) _show without docid returns 500 instead of 404 In-Reply-To: <686581823.1260744318088.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COUCHDB-598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12790250#action_12790250 ] Jason Davies commented on COUCHDB-598: -------------------------------------- I think this is the expected behaviour, and the example in the book is probably at fault. We used to return a 404 when the document didn't exist, but we needed the ability to define a custom response for non-existent docs e.g. a custom 404 page, or a 302 redirect, so now we pass null to the show function instead. As your show function doesn't handle the case when doc === null, it is raising an exception and causing a 500 error. Your code should test for doc === null and return {code: 404, ...} to avoid the 500 error. I propose marking this as wontfix, any objections? > _show without docid returns 500 instead of 404 > ---------------------------------------------- > > Key: COUCHDB-598 > URL: https://issues.apache.org/jira/browse/COUCHDB-598 > Project: CouchDB > Issue Type: Bug > Components: HTTP Interface > Affects Versions: 0.10 > Environment: Ubuntu Karmic > Reporter: Markus > Priority: Minor > > See also the thread on the mailing list::http://www.mail-archive.com/user@couchdb.apache.org/msg05633.html and especially the following quote from Chris Anderson :" The change would be simple, just remove a catch clause on couch_httpd_show.erl line 81." > Original message below: > ------ > 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 > '

'+doc.title+'

'+doc.body+'

'; } " > } > } > 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 :

title

body text

> 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 "

" + doc.title + "

" + > doc.body + "

";},null,[object Object],"function (doc, req) { return > '

'+doc.title+'

'+doc.body+'

'; } > ")@/usr/share/couchdb/server/main.js:388 > ("function (doc, req) { return '

'+doc.title+'

'+doc.body > +'

'; } ",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">>, > <<"

Render > Error

JavaScript function raised error: TypeError: doc is > null

Stacktrace:

(null,[object Object])@:0
> \nrunShow(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\n(\"function (doc, req)
> { return '<h1>'+doc.title+'</h1><p>'+doc.body
> +'</p>'; } \",null,[object
> Object])@/usr/share/couchdb/server/main.js:358
> \n@/usr/share/couchdb/server/main.js:842\n

Function > source:

function (doc, req) { return
> '<h1>'+doc.title+'</h1><p>'+doc.body+'</p>'; }
> 
">>}]}} > [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. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.