{"id":8101,"date":"2015-11-26T13:39:48","date_gmt":"2015-11-26T13:39:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/cloudant-case_clause-error-with-pouchdb-when-replicating-open-source-projects-pouchdb-pouchdb\/"},"modified":"2022-08-30T15:03:01","modified_gmt":"2022-08-30T15:03:01","slug":"cloudant-case_clause-error-with-pouchdb-when-replicating-open-source-projects-pouchdb-pouchdb","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/26\/cloudant-case_clause-error-with-pouchdb-when-replicating-open-source-projects-pouchdb-pouchdb\/","title":{"rendered":"Cloudant &#8220;case_clause&#8221; error with pouchdb when replicating-open source projects pouchdb\/pouchdb"},"content":{"rendered":"<p>I am working with Pouchdb and Cloudant, and when my web app starts up it does a replication from Cloudant down to my pouchdb in the browser. I have an idea of how pouchdb works internally, and this is how I believe the process works (high level):<\/p>\n<ol>\n<li>Replication starts<\/li>\n<li>Gets a checkpoint doc from cloudant db (contains latest sequence number retrived from server, if not exists, assumes sequence # is 0, which is my case)<\/li>\n<li>Grabs the changes from the changes freed starting at that sequence number (it grabs up to 25 changes)<\/li>\n<li>Writes(or updates) the checkpoint doc back to cloudant server with the new sequence number (this way if a network error occurs, it can continue where it left off or for the next replication)<\/li>\n<li>Repeats until no changes left<\/li>\n<li>Replication complete<\/li>\n<\/ol>\n<p>The problem is at step 4, that when pouch tries to write that doc to the cloudant server (for the first time), the server returns a &#8216;case_clause&#8217; error. I am thinking the issue might be an invalid id sent to cloudant (cloudant doesn&#8217;t accept ids of this format), because the id of the doc written to the server is <code>_local\/799c37dfaefb3774a04f55c7f8cee947<\/code> (or other random numbers and characters at the end). I don&#8217;t know if that is a valid doc id or not (for cloudant that is, because this is accurate for pouchdb), so I guess I am asking, is that the issue (unacceptable id for cloudant), or is there some other issue based on the error the cloudant server returns.<\/p>\n<p>Here is the doc being written:<\/p>\n<pre>{\n    _id: \"_local\/799c37dfaefb3774a04f55c7f8cee947\",\n    last_seq: \"63\"\n}\n<\/pre>\n<p>Here is the full error output from Chrome debugger:<\/p>\n<pre>{\n    error: \"case_clause\"\n    reason: \"{{case_clause,{ok,{error,[{{doc,&gt;,\n                                {338,\n                                [&gt;]},\n                                {[{&gt;,&gt;}]},\n                                [],false,[]},\n                          {error,internal_server_error}}]}}},\n    [{fabric,update_doc,3},{chttpd_db,'-update_doc\/6-fun-0-',3}]}\"\n    stack: Array[4]\n    0: \"chttpd_db:update_doc\/6\"\n    1: \"chttpd:handle_request\/1\"\n    2: \"mochiweb_http:headers\/5\"\n    3: \"proc_lib:init_p_do_apply\/3\"\n    length: 4\n    __proto__: Array[0]\n    status: 500\n}<\/pre>\n<p>Note: When I go into cloudant&#8217;s Futon and manually enter the url for the checkpoint doc using its id, it does not exist. Thanks<\/p>\n<p>EDIT:<\/p>\n<p>Header Info from the above request using Chrome debugger:<\/p>\n<pre>\nRequest URL:http:\/\/lessontrek.toddbluhm.c9.io\/db\/ilintindingreseseldropec\/_local%2F799c37dfaefb3774a04f55c7f8cee947\nRequest Method:PUT\nStatus Code:500 Internal Server Error\nRequest Headersview parsed\nPUT \/db\/ilintindingreseseldropec\/_local%2F799c37dfaefb3774a04f55c7f8cee947 HTTP\/1.1\nHost: lessontrek.toddbluhm.c9.io\nConnection: keep-alive\nContent-Length: 111\nAccept: application\/json\nOrigin: http:\/\/lessontrek.toddbluhm.c9.io\nUser-Agent: Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/28.0.1500.71 Safari\/537.36\nContent-Type: application\/json\nReferer: http:\/\/lessontrek.toddbluhm.c9.io\/app\nAccept-Encoding: gzip,deflate,sdch\nAccept-Language: en-US,en;q=0.8\nCookie: connect.sid=s%3A8MVBFmbizTX4VNOqZNtIuxQI.TZ9yKRqNv0ePbTB%2FmSpJsncYszJ8qBSD5EWHzxQYIbg; AuthSession=(removed for security purposes, but valid); db_name=ilintindingreseseldropec; __utma=200306492.386329876.1368934655.1375164160.1375252679.55; __utmc=200306492; __utmz=200306492.1372711539.22.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); c9.live.proxy=(removed for security purposes, but valid)\nRequest Payloadview parsed\n{\"_id\":\"_local\/799c37dfaefb3774a04f55c7f8cee947\",\"last_seq\":\"63\",\"_rev\":\"338-7db9750558e43e2076a3aa720a6de47b\"}\nResponse Headersview parsed\nHTTP\/1.1 500 Internal Server Error\nx-powered-by: Express\nvary: Accept-Encoding\nx-couch-request-id: 7d2ca9fc\nserver: CouchDB\/1.0.2 (Erlang OTP\/R14B)\ndate: Wed, 31 Jul 2013 07:29:23 GMT\ncontent-type: application\/json\ncache-control: must-revalidate\ncontent-encoding: gzip\ntransfer-encoding: chunked\nvia: 1.1 project-livec993c2dc8b8c.rhcloud.com (node-web-proxy\/0.4)\nX-C9-Server: proxy_subdomain_collab-bus2_01\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am working with Pouchdb and Cloudant, and when my web app starts up it does a replication from Cloudant down to my pouchdb in the browser. I have an idea of how pouchdb works internally, and this is how I believe the process works (high level): Replication starts Gets a checkpoint doc from cloudant [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8101","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8101"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8101\/revisions"}],"predecessor-version":[{"id":8622,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8101\/revisions\/8622"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}