You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/07 17:37:51 UTC

[29/50] couch commit: updated refs/heads/windsor-merge to 6e60cbe

Gracefully handle design document updates with malformatted structure

The existing code will break with a badmatch when a user attempts to
insert a design document with the following structure:

    {"_id": "_design/test",
     "views": "a string"}

This badmatch bubbles up to the user as an HTTP 500 with a nasty function
clause stacktrace[1].

With this patch, the user sees a clean HTTP 400 with a description of the
error[2].

[1]: https://gist.github.com/banjiewen/8dd395f152eef9269d77
[2]: https://gist.github.com/banjiewen/ae665af65171fb7c6572

BugzID: 23081


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/2ca323c0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/2ca323c0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/2ca323c0

Branch: refs/heads/windsor-merge
Commit: 2ca323c0d480127f8bd10365a0bc8cfe16cb03d3
Parents: 13b4e43
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Mon Sep 30 16:18:55 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Aug 6 11:12:59 2014 +0100

----------------------------------------------------------------------
 src/couch_db.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2ca323c0/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index b0c7894..4adb128 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -548,6 +548,8 @@ validate_ddoc(DbName, DDoc) ->
     try
         couch_index_server:validate(DbName, couch_doc:with_ejson_body(DDoc))
     catch
+        throw:{invalid_design_doc, Reason} ->
+            {bad_request, invalid_design_doc, Reason};
         throw:Error ->
             Error
     end.