couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Newson (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (COUCHDB-1528) Error messages for malformed show functions are unhelpful
Date Mon, 27 Aug 2012 14:15:08 GMT

     [ https://issues.apache.org/jira/browse/COUCHDB-1528?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Robert Newson updated COUCHDB-1528:
-----------------------------------

    Summary: Error messages for malformed show functions are unhelpful  (was: send headers
on a Show Function causes badarg error)

Instead of a useful message for some show function errors, the user receives only;

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

Two cases are identified;

start({headers: {"Content-Type": "text/javascript"}});

This gives badarg, the correct code is;

start({"Content-Type": "text/javascript"});

The second case is;

return({headers : {"Content-Length" : 3});

as the header name and header value are forced through erlang:binary_to_list in all cases.
                
> Error messages for malformed show functions are unhelpful
> ---------------------------------------------------------
>
>                 Key: COUCHDB-1528
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1528
>             Project: CouchDB
>          Issue Type: Bug
>          Components: Database Core, HTTP Interface
>    Affects Versions: 1.2
>         Environment: Windows XP sp3
>            Reporter: Osher E
>              Labels: content-type, http-headers, show-function
>
> h2. send headers on a Show Function causes badarg error
> h3. Request
> {code}
> http://dev.server.com:5984/db/_design/app/_show/env_settings/app1-dev?callback=$r
> {code}
> h3. Response
> {code}
> 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"}
> {code}
> h3. 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}]}]
> {code}
> h2. more info
> h3. The show function
> {code}
>  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)
>     }
> {code}
> Tried also
> {code}
>         out = out.join("");
>         return { 
>           headers: 
>             { "Content-Type"  : "text/javascript"
>             , "Content-Length": out.length
>             }
>         , body: out
>         }
> {code}
> and 
> {code}
>            { "Content-Type"  : "text/javascript; charset=utf-8"
>             , "Content-Length": out.length
>             }
> {code}
> got same result
> works only when the entire headers part is commented out.
> h3. Sample document:
> {code}
> {
>    "_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/"
>    }
> }
> {code}
> 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*
> {code}
> opm.dev.couch.com = /db/_design/app/_rewrite
> {code}
> *rewrite section*
> {code}
>   , rewrites : 
>     [ {from:"/of/*", to:'_show/env_settings/*'}
>     , {from:"/*"   , to:'*'}
>     ]
> {code}
> h3. expected output (beautified)
> {code}
> $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/"
>     }
>   }
> )
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message