特定文档上的CouchDB错误:“HTTP请求中的function_clause错误”

时间:2011-06-08 22:00:13

标签: couchdb attachment

我有一个CouchDB数据库,我在其中存储包含PDF和PNG附件的文档。在特定文档上保存附件后,show函数在尝试在浏览器中查看该文档时失败。浏览器中的消息是:

{"error":"unknown_error","reason":"function_clause"}

couch.log中的错误是

[Wed, 08 Jun 2011 21:29:58 GMT] [error] [<0.106.0>] function_clause error in HTTP request

[Wed, 08 Jun 2011 21:29:58 GMT] [info] [<0.106.0>] Stacktrace: [{couch_httpd,doc_etag,
             [{'EXIT',
                  {{case_clause,
                       {[{<<"author">>,
                          [<<"Brian St. Claire-King">>,
                           <<"Eloy LaSanta">>]},
                         {<<"book_type">>,[<<"Roleplaying Game">>]},
                         {<<"date_added">>,[2011,6,7]},
                         {<<"date_published">>,2008},
                         {<<"genre">>,
                          [<<"Futuristic">>,<<"Post-Apocalyptic">>]},
                         {<<"language">>,<<"English">>},
                         {<<"license">>,
                          [{[{<<"url">>,<<"http://www.lulu.com">>},
                             {<<"id">>,<<"4880508">>}]}]},
                         {<<"page_count">>,276},
                         {<<"publisher">>,<<"Vajra Enterprises">>},
                         {<<"subtitle">>,<<"The Role Playing Game">>},
                         {<<"system">>,[<<"Organic Rule Components">>]},
                         {<<"title">>,<<"KidWorld">>},
                         {<<"last_modified">>,
                          <<"2011-06-08T01:58:44.697Z">>},
                         {<<"publisher_url">>,
                          <<"http://www.vajraenterprises.com/">>}]}},
                   [{couch_btree,lookup,3},
                    {couch_btree,lookup_kpnode,5},
                    {couch_btree,lookup,2},
                    {couch_db,get_full_doc_info,2},
                    {couch_db,open_doc_int,3},
                    {couch_db,open_doc,3},
                    {couch_httpd_db,couch_doc_open,4},
                    {couch_httpd_show,maybe_open_doc,2}]}}]},
         {couch_httpd_show,show_etag,4},
         {couch_httpd_show,handle_doc_show,6},
         {couch_httpd_db,do_db_req,2},
         {couch_httpd,handle_request_int,5},
         {mochiweb_http,headers,5},
         {proc_lib,init_p_do_apply,3}]

[Wed, 08 Jun 2011 21:29:58 GMT] [info] [<0.106.0>] 127.0.0.1 - - 'GET' /bookshelf/_design/bookshelf_loader/_show/book/4ddbbd8f3fd780c65e03c0a5e901fd57 500

我只能猜测其中一个附件已损坏。我已经尝试在Futon Test Suite中运行适用于附件的测试; “附件”测试运行了12个多小时而未完成。

我只是删除了该文档,但我没有修订号,任何访问该文档的尝试都失败了。我尝试使用cURL查询_all_docs视图,但是它被中途中断并出现错误:

{"id":"40af854814db1b4890c37c669a11de28","key":"40af854814db1b4890c37c669a11de28","value":{"rev":"4-ff85b5dbb2e4800ab4bfee81f32f0866"}}
curl: (56) Received problem 2 in the chunky parser

有没有办法可以删除违规文件(或其附件)只知道_id而不是_rev?

编辑:我翻回日志并发现了最初的崩溃,如下所示:

[Wed, 08 Jun 2011 02:00:05 GMT] [error] [<0.679.0>] ** Generic server <0.679.0> terminating 
** Last message in was {update_docs,<0.4902.0>,
                       [[{doc,<<"4ddbbd8f3fd780c65e03c0a5e901fd57">>,
                             {4,
                              [<<81,240,217,60,28,224,204,196,19,243,27,
                                 111,230,88,90,205>>,
                               <<171,3,185,48,48,23,182,2,95,122,48,132,
                                 184,105,254,242>>,
                               <<69,27,210,166,21,121,125,192,47,237,187,
                                 37,74,195,109,22>>,
                               <<145,31,9,71,4,24,15,90,97,154,177,102,
                                 151,156,111,34>>]},
                             {[{<<"author">>,
                                [<<"Brian St. Claire-King">>,
                                 <<"Eloy LaSanta">>]},
                               {<<"book_type">>,[<<"Roleplaying Game">>]},
                               {<<"date_added">>,[2011,6,7]},
                               {<<"date_published">>,2008},
                               {<<"genre">>,
                                [<<"Futuristic">>,<<"Post-Apocalyptic">>]},
                               {<<"language">>,<<"English">>},
                               {<<"license">>,
                                [{[{<<"url">>,<<"http://www.lulu.com">>},
                                   {<<"id">>,<<"4880508">>}]}]},
                               {<<"page_count">>,276},
                               {<<"publisher">>,<<"Vajra Enterprises">>},
                               {<<"subtitle">>,
                                <<"The Role Playing Game">>},
                               {<<"system">>,
                                [<<"Organic Rule Components">>]},
                               {<<"title">>,<<"KidWorld">>},
                               {<<"last_modified">>,
                                <<"2011-06-08T01:58:44.697Z">>},
                               {<<"publisher_url">>,
                                <<"http://www.vajraenterprises.com/">>}]},
                             [{att,<<"KidWorld_2010_for_pdf.pdf">>,
                                  <<"application/pdf">>,76729048,76729048,
                                  <<143,119,231,165,202,3,166,134,23,195,
                                    94,84,227,25,87,193>>,
                                  4,
                                  {<0.676.0>,[4280434790]},
                                  identity},
                              {att,<<"kidworld copy.png">>,
                                  <<"image/png">>,21674,21674,
                                  <<237,107,129,30,82,36,136,61,29,17,202,
                                    217,209,88,187,125>>,
                                  3,
                                  {<0.676.0>,[4280406118]},
                                  identity}],
                             false,[]}]],
                       [],false,false}
** When Server state == {db,<0.678.0>,<0.679.0>,nil,<<"1307486659185780">>,
                        <0.676.0>,<0.680.0>,
                        {db_header,5,2454,0,
                            {4280430351,{508,9}},
                            {4280431672,517},
                            nil,0,nil,nil,1000},
                        2454,
                        {btree,<0.676.0>,
                            {4280430351,{508,9}},
                            #Fun<couch_db_updater.7.69395062>,
                            #Fun<couch_db_updater.8.86519079>,
                            #Fun<couch_btree.5.124754102>,
                            #Fun<couch_db_updater.9.24674233>},
                        {btree,<0.676.0>,
                            {4280431672,517},
                            #Fun<couch_db_updater.10.90337910>,
                            #Fun<couch_db_updater.11.13595824>,
                            #Fun<couch_btree.5.124754102>,
                            #Fun<couch_db_updater.12.34906778>},
                        {btree,<0.676.0>,nil,
                            #Fun<couch_btree.0.83553141>,
                            #Fun<couch_btree.1.30790806>,
                            #Fun<couch_btree.2.124754102>,nil},
                        2454,<<"bookshelf">>,
                        "../var/lib/couchdb/bookshelf.couch",[],[],nil,
                        {user_ctx,null,[],undefined},
                        nil,1000,
                        [before_header,after_header,on_file_open],
                        false}
** Reason for termination == 
** {{case_clause,{[{<<"author">>,
                [<<"Brian St. Claire-King">>,<<"Eloy LaSanta">>]},
               {<<"book_type">>,[<<"Roleplaying Game">>]},
               {<<"date_added">>,[2011,6,7]},
               {<<"date_published">>,2008},
               {<<"genre">>,[<<"Futuristic">>,<<"Post-Apocalyptic">>]},
               {<<"language">>,<<"English">>},
               {<<"license">>,
                [{[{<<"url">>,<<"http://www.lulu.com">>},
                   {<<"id">>,<<"4880508">>}]}]},
               {<<"page_count">>,276},
               {<<"publisher">>,<<"Vajra Enterprises">>},
               {<<"subtitle">>,<<"The Role Playing Game">>},
               {<<"system">>,[<<"Organic Rule Components">>]},
               {<<"title">>,<<"KidWorld">>},
               {<<"last_modified">>,<<"2011-06-08T01:58:44.697Z">>},
               {<<"publisher_url">>,
                <<"http://www.vajraenterprises.com/">>}]}},
[{couch_btree,modify_node,4},
 {couch_btree,modify_kpnode,6},
 {couch_btree,modify_node,4},
 {couch_btree,query_modify,4},
 {couch_btree,add_remove,3},
 {couch_db_updater,update_docs_int,5},
 {couch_db_updater,handle_info,2},
 {gen_server,handle_msg,5}]}


[Wed, 08 Jun 2011 02:00:06 GMT] [error] [<0.679.0>] {error_report,<0.33.0>,
{<0.679.0>,crash_report,
 [[{initial_call,{couch_db_updater,init,['Argument__1']}},
   {pid,<0.679.0>},
   {registered_name,[]},
   {error_info,
       {exit,
           {{case_clause,
                {[{<<"author">>,
                   [<<"Brian St. Claire-King">>,<<"Eloy LaSanta">>]},
                  {<<"book_type">>,[<<"Roleplaying Game">>]},
                  {<<"date_added">>,[2011,6,7]},
                  {<<"date_published">>,2008},
                  {<<"genre">>,[<<"Futuristic">>,<<"Post-Apocalyptic">>]},
                  {<<"language">>,<<"English">>},
                  {<<"license">>,
                   [{[{<<"url">>,<<"http://www.lulu.com">>},
                      {<<"id">>,<<"4880508">>}]}]},
                  {<<"page_count">>,276},
                  {<<"publisher">>,<<"Vajra Enterprises">>},
                  {<<"subtitle">>,<<"The Role Playing Game">>},
                  {<<"system">>,[<<"Organic Rule Components">>]},
                  {<<"title">>,<<"KidWorld">>},
                  {<<"last_modified">>,<<"2011-06-08T01:58:44.697Z">>},
                  {<<"publisher_url">>,
                   <<"http://www.vajraenterprises.com/">>}]}},
            [{couch_btree,modify_node,4},
             {couch_btree,modify_kpnode,6},
             {couch_btree,modify_node,4},
             {couch_btree,query_modify,4},
             {couch_btree,add_remove,3},
             {couch_db_updater,update_docs_int,5},
             {couch_db_updater,handle_info,2},
             {gen_server,handle_msg,5}]},
           [{gen_server,terminate,6},{proc_lib,init_p_do_apply,3}]}},
   {ancestors,[<0.678.0>,<0.675.0>]},
   {messages,[]},
   {links,[<0.678.0>]},
   {dictionary,[]},
   {trap_exit,true},
   {status,running},
   {heap_size,6765},
   {stack_size,24},
   {reductions,65012}],
  []]}}

这是我的_show功能。我没有任何_update函数。

function(doc, req) {  
  var ddoc = this;
  var Mustache = require("lib/mustache");
  var path = require("vendor/couchapp/lib/path").init(req);
  var indexPath = path.list('index','recent-books',{descending:true, limit:25});

  var data = {
    header : {
      index : indexPath,
      headerTitle : "Bookshelf"
    },
    scripts : {
        assets : path.asset()
    },
index : indexPath,
    pageTitle : doc ? "Edit: " + doc.title : "Create a new book",
    assets : path.asset(),
db : req.path[0]
  };

  if (doc) {
    data.doc = JSON.stringify(doc);
    data.author = doc.author;
    data.book_types = getCheckboxValues(bookTypeArray, doc.book_type);
    data.book_type_other = getOthers(bookTypeArray, doc.book_type);
    data.cover_image = getAttachmentName(doc._attachments, "image/png");
    data.date_added = getDateString(doc.date_added);        
    data.date_published = doc.date_published;
    data.edition = doc.edition;
    data.issue_number = doc.issue_number;
    data.file_name = getAttachmentName(doc._attachments, "application/pdf");
    data.genres = getCheckboxValues(genreArray, doc.genre);
    data.genre_other = getOthers(genreArray, doc.genre);
    data._id = doc._id;
    data.languages = getDropdownValues(languageArray, doc.language);
    data.licenses = getLicenses(doc.license);
    data.page_count = doc.page_count;
    data.publishers = getDropdownValues(publisherArray, doc.publisher);
    data.publisher_other = getOther(publisherArray, doc.publisher);
    data.publisher_url = doc.publisher_url;
    data._rev = doc._rev;
    data.subtitle = doc.subtitle;
    data.systems = getCheckboxValues(systemArray, doc.system);
    data.system_other = getOthers(systemArray, doc.system);
    data.tags = doc.tags;
    data.title = doc.title;
    data.version = doc.version;
  } else {
    data.doc = JSON.stringify({});
    data.date_added = getDateString();
    data.book_types = getCheckboxValues(bookTypeArray);
    data.languages = getDropdownValues(languageArray, "English");
    data.licenses = "http://www.drivethrurpg.com,";
    data.publishers = getDropdownValues(publisherArray);
    data.genres = getCheckboxValues(genreArray);
    data.systems = getCheckboxValues(systemArray);
  }
  return Mustache.to_html(ddoc.templates.edit, data, ddoc.templates.partials);
}

我没有粘贴所有相对简单的帮助函数(例如getCheckboxValues),这些函数在Couch中存储的内容与屏幕上的内容之间进行转换,但如果您认为它们是有益的话我可以。

我终于能够访问旧视图并获取文档的_rev。但是,使用cURL发出DELETE命令会导致与之前相同的“case_clause”错误。任何将新文档PUT或POST到数据库中的尝试都将无限期地挂起,从那时起数据库就无法访问。 (幸运的是我有一个备份副本,它仍然有一个损坏的文件,但至少可以访问。)

1 个答案:

答案 0 :(得分:8)

正如@JasonSmith在上面的评论中提到的,这有时可能是由于Javascript中的错误造成的。我偶然地将View的name属性直接设置为函数而不是包含其map和可选reduce函数的对象,偶然发现了同样的错误消息。 AKA

为:

"views": {
    "test_view": "function (doc) { ... }"
 }

好:

"views": {
   "test_view": {
       "map": "function (doc) { ... }"
   }
}