[ 
https://issues.apache.org/jira/browse/COUCHDB-3305?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15876949#comment-15876949
 ] 

ASF GitHub Bot commented on COUCHDB-3305:
-----------------------------------------

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
    
----

----


> don't crash with invalid input to built in reducer function
> -----------------------------------------------------------
>
>                 Key: COUCHDB-3305
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-3305
>             Project: CouchDB
>          Issue Type: Improvement
>          Components: Database Core
>            Reporter: Tony Sun
>            Assignee: Tony Sun
>
> When users use a built in reduce function such as _sum, and documents have 
> invalid input, we currently crash and return a 500 with error message. This 
> improvement will return an error row without crashing for better debugging.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to