couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Candler (JIRA)" <>
Subject [jira] Created: (COUCHDB-336) Would like errors in map function to be reported to client
Date Tue, 28 Apr 2009 09:08:30 GMT
Would like errors in map function to be reported to client

                 Key: COUCHDB-336
             Project: CouchDB
          Issue Type: Wish
         Environment: svn trunk 0.10.0a768591
            Reporter: Brian Candler
            Priority: Minor

At the moment, if a runtime error occurs in a map function, the document is silently excluded
from the view and the client is none the wiser.

$ curl -X PUT
$ curl -d '{"foo":"bar"}' -X PUT
$ curl -d '{"food":"bar"}' -X PUT

# Example 1: map function calls undefined function
$ curl -d '{"map":"function(doc) { emitt(null,null); }"}' -H 'Content-Type: application/json'

# Example 2: map function attempts to emit 'undefined'
$ curl -d '{"map":"function(doc) { emit(doc._id,; }"}' -H 'Content-Type: application/json'

Of course, errors are available in the server log:

[Tue, 28 Apr 2009 08:40:39 GMT] [info] [<0.1276.0>] OS Process Log Message: function
raised exception (ReferenceError: emitt is not defined) with doc._id doc1
[Tue, 28 Apr 2009 08:43:44 GMT] [info] [<0.1276.0>] OS Process Log Message: function
raised exception (Cannot encode 'undefined' value as JSON) with doc._id doc2

But the client cannot see these, and worse, gets what appears to be a valid result set.

I think there are two cases to consider.

- in temporary views, it ought to be easy to do something: e.g. (1) return the full set of
failed docs with their errors, or (2) return a count of failed docs, or (3) just abort on
the first error

- in permanent views, it might also be useful to return this information, but it could be
expensive to persist. Also, when you're querying for key X you might not want to see a whole
load of errors for unrelated docs. An error count might be OK though, similar to total_rows.

The current behaviour may be useful, although I personally wouldn't want to rely on it, especially
as it generates errors in the log. That is, I would rather be forced to rewrite example 2

  function(doc) { if ( { emit(doc._id,; } }
  function(doc) { emit(doc._id, || null); }

as appropriate.

Workaround: users can manually wrap each of their map functions in a catcher which emits a
sentinel key/value pair containing the error. However they would still have to query the key
range which includes the error messages.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message