Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-1528

Error messages for malformed show functions are unhelpful

    XMLWordPrintableJSON

Details

    Description

      send headers on a Show Function causes badarg error

      Request

      http://dev.server.com:5984/db/_design/app/_show/env_settings/app1-dev?callback=$r
      

      Response

      500 Internal Server Error
      Cache-Control:must-revalidate
      Content-Length:44
      Content-Type:text/plain; charset=utf-8
      Date:Mon, 27 Aug 2012 13:22:14 GMT
      Server:CouchDB/1.2.0 (Erlang OTP/R15B)
      
      {"error":"unknown_error","reason":"badarg"}
      

      Log entries:

      {code]
      [Mon, 27 Aug 2012 12:58:50 GMT] [error] [<0.6956.3>] Badarg error in HTTP request
      [Mon, 27 Aug 2012 12:58:50 GMT] [info] [<0.6956.3>] Stacktrace: [{erlang,binary_to_list,
      [{[

      {<<"Content-Type">>, <<"text/javascript">>}

      ]}],
      []},
      {couch_httpd_external,
      'parse_external_response/1-fun-0',1,
      [

      {file, "d:/relax/couchdb/src/couchdb/couch_httpd_external.erl"}

      ,

      {line,157}

      ]},
      {lists,map,2,
      [

      {file,"lists.erl"},{line,1173}]},
      {lists,map,2,
      [{file,"lists.erl"}

      ,

      {line,1173}

      ]},
      {couch_httpd_external,
      'parse_external_response/1-fun-1',2,
      [

      {file, "d:/relax/couchdb/src/couchdb/couch_httpd_external.erl"}

      ,

      {line,156}

      ]},
      {lists,foldl,3,
      [

      {file,"lists.erl"}

      ,

      {line,1197}

      ]},
      {couch_httpd_external,
      send_external_response,2,
      [

      {file, "d:/relax/couchdb/src/couchdb/couch_httpd_external.erl"}

      ,

      {line,129}

      ]},
      {couch_httpd_db,do_db_req,2,
      [

      {file, "d:/relax/couchdb/src/couchdb/couch_httpd_db.erl"}

      ,

      {line,230}

      ]}]

      h2. more info
      
      h3. The show function
      

      function(doc, req){
      var u
      , urls = doc.uses
      , out =
      [ req.query.callback || "callback"
      , "({app:\"", doc.app || ""
      , "\",env:\"" , doc.env
      , "\",ver:" , doc._rev.substr(0,doc._rev.indexOf("-"))
      , ",uses:{"
      ];

      for (u in urls)
      out.push(u,":\"",urls[u],"\"",",");
      out[out.length-1] = "}});";

      start({headers: {"Content-Type": "text/javascript"}});
      out.forEach(send)
      }

      Tried also
      
      

      out = out.join("");

      return {
      headers:

      { "Content-Type" : "text/javascript" , "Content-Length": out.length }

      , body: out
      }

      and 
      
      { "Content-Type" : "text/javascript; charset=utf-8" , "Content-Length": out.length }
      got same result
      
      works only when the entire headers part is commented out.
      
      h3. Sample document:
      

      {
      "_id": "app1-dev",
      "_rev": "10-269755da4f2c8ed771d9b301ec7d6163",
      "env": "dev",
      "app": "app1",
      "uses":

      { "front": "http://dev.server.com/front/", "auth": "http://qas.server.com/auth/", "back": "http://dev.server.com/back/" }

      }

      h3. configuration
      produced with WindowsXP, couch 1.2.0, OTP R15.
      
      I first noted the problem accessing through vhost + _rewrite. However, the problem is reproduced also without.
      
      *vhosts setting*
      

      opm.dev.couch.com = /db/_design/app/_rewrite

      *rewrite section*
      

      , rewrites :
      [

      {from:"/of/*", to:'_show/env_settings/*'}

      ,

      {from:"/*" , to:'*'}

      ]

      
      h3. expected output (beautified)
      
      

      $r(
      { app : "app1"
      , env : "dev"
      , ver : 10
      , uses:

      { front: "http://dev.server.com/front/" , auth: "http://qas.server.com/auth/" , back: "http://dev.server.com/back/" }

      }
      )

      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            osher Osher E
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: