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

don't crash with invalid input to built in reducer function

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Database Core
    • Labels:
      None

      Description

      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.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          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



          Show
          githubbot ASF GitHub Bot added a comment - 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
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 9f9c48221a96452f36790aa8dd52c557d65b9cde in couchdb-couch's branch refs/heads/master from Tony Sun
          [ https://git-wip-us.apache.org/repos/asf?p=couchdb-couch.git;h=9f9c482 ]

          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.

          COUCHDB-3305

          Show
          jira-bot ASF subversion and git services added a comment - Commit 9f9c48221a96452f36790aa8dd52c557d65b9cde in couchdb-couch's branch refs/heads/master from Tony Sun [ https://git-wip-us.apache.org/repos/asf?p=couchdb-couch.git;h=9f9c482 ] 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. COUCHDB-3305
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/couchdb-couch/pull/229

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/couchdb-couch/pull/229
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user iilyak opened a pull request:

          https://github.com/apache/couchdb-couch/pull/234

          Fix initial accumulator value for builtin_sum_rows

          This a fixup for https://github.com/apache/couchdb-couch/pull/229.
          The initial value for accumulator suppose to be 0. Since the result of
          sum and count is integer. The problem was discovered by dialyzer.

          COUCHDB-3305

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/cloudant/couchdb-couch 70794-fix-initial-acc-for-builtin_sum_rows

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/couchdb-couch/pull/234.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 #234


          commit 1f152daaac23dc96132139fb532786f77becdd64
          Author: ILYA Khlopotov <iilyak@apache.org>
          Date: 2017-03-08T20:24:46Z

          Fix initial accumulator value for builtin_sum_rows

          This a fixup for https://github.com/apache/couchdb-couch/pull/229.
          The initial value for accumulator suppose to be 0. Since the result of
          sum and count is integer. The problem was discovered by dialyzer.

          COUCHDB-3305


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user iilyak opened a pull request: https://github.com/apache/couchdb-couch/pull/234 Fix initial accumulator value for builtin_sum_rows This a fixup for https://github.com/apache/couchdb-couch/pull/229 . The initial value for accumulator suppose to be 0. Since the result of sum and count is integer. The problem was discovered by dialyzer. COUCHDB-3305 You can merge this pull request into a Git repository by running: $ git pull https://github.com/cloudant/couchdb-couch 70794-fix-initial-acc-for-builtin_sum_rows Alternatively you can review and apply these changes as the patch at: https://github.com/apache/couchdb-couch/pull/234.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 #234 commit 1f152daaac23dc96132139fb532786f77becdd64 Author: ILYA Khlopotov <iilyak@apache.org> Date: 2017-03-08T20:24:46Z Fix initial accumulator value for builtin_sum_rows This a fixup for https://github.com/apache/couchdb-couch/pull/229 . The initial value for accumulator suppose to be 0. Since the result of sum and count is integer. The problem was discovered by dialyzer. COUCHDB-3305
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 1f152daaac23dc96132139fb532786f77becdd64 in couchdb-couch's branch refs/heads/master from ILYA Khlopotov
          [ https://git-wip-us.apache.org/repos/asf?p=couchdb-couch.git;h=1f152da ]

          Fix initial accumulator value for builtin_sum_rows

          This a fixup for https://github.com/apache/couchdb-couch/pull/229.
          The initial value for accumulator suppose to be 0. Since the result of
          sum and count is integer. The problem was discovered by dialyzer.

          COUCHDB-3305

          Show
          jira-bot ASF subversion and git services added a comment - Commit 1f152daaac23dc96132139fb532786f77becdd64 in couchdb-couch's branch refs/heads/master from ILYA Khlopotov [ https://git-wip-us.apache.org/repos/asf?p=couchdb-couch.git;h=1f152da ] Fix initial accumulator value for builtin_sum_rows This a fixup for https://github.com/apache/couchdb-couch/pull/229 . The initial value for accumulator suppose to be 0. Since the result of sum and count is integer. The problem was discovered by dialyzer. COUCHDB-3305
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/couchdb-couch/pull/234

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/couchdb-couch/pull/234

            People

            • Assignee:
              tonysun83 Tony Sun
              Reporter:
              tonysun83 Tony Sun
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Development