couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [10/50] couch commit: updated refs/heads/master to 9d0ac7d
Date Thu, 28 Aug 2014 12:11:46 GMT
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/60aa4191
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/60aa4191
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/60aa4191

Branch: refs/heads/master
Commit: 60aa419115fa631e522d0f3a63e77e9cb22e4b73
Parents: 3483d90
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Mon Sep 30 16:18:55 2013 -0700
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Aug 28 13:00:00 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/60aa4191/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.


Mime
View raw message