GitHub user tonysun83 opened a pull request:
https://github.com/apache/couchdb-couch/pull/229
Return error row instead of crashing
When input is invalid for built in reducers, we return an error row
instead of crashing. Thanks to @davisp for providing the elegant
solution.
The results now look like this:
```
{
"rows": [
{
"key": null,
"value": {
"key": [],
"value": [
{
"a": 1
},
{
"a": 2
},
{
"a": 3
},
{
"a": 4
}
],
"builtin_reduce_error": "The _sum function requires that
map values be numbers, arrays of numbers, or objects, not '[{[{<<\"b\">>,\n
1}]},\n
{[{<<\"b\">>,\n
2}]},\n
{[{<<\"b\">>,\n
3}]},\n
{[{<<\"b\">>,\n
4}]}]'. Objects cannot be mixed with other data structures. Objects can be
arbitrarily nested, provided that the values for
all fields are themselves numbers, arrays of numbers, or objects."
}
}
]
}
```
I didn't change the initial error message, as it was quite informative.
Another bonus for this change
is that the log isn't flooded with error messages.
COUCHDB-3305
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cloudant/couchdb-couch 70794-reduce-sum-errors
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/couchdb-couch/pull/229.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #229
----
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---