You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/05 00:06:41 UTC
[28/50] couch commit: updated refs/heads/import to c3116d7
Reject design docs with compilation errors
If we know the language for a given design doc we'll attempt to compile
the map/reduce functions and reject updates that introduce code that
doesn't compile. We don't yet do the other types of functions because
those errors are more user visible.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/22fdbe2e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/22fdbe2e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/22fdbe2e
Branch: refs/heads/import
Commit: 22fdbe2e4c8c4372fadfd714cf45211bfdd5cff3
Parents: a7d1663
Author: Paul J. Davis <pa...@gmail.com>
Authored: Sun Mar 10 16:03:00 2013 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 17:03:24 2014 -0600
----------------------------------------------------------------------
src/couch_db.erl | 15 +++++++++++++--
src/couch_query_servers.erl | 12 ++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/22fdbe2e/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 56cb0d2..7734c7c 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -502,8 +502,11 @@ group_alike_docs([{Doc,Ref}|Rest], [Bucket|RestBuckets]) ->
group_alike_docs(Rest, [[{Doc,Ref}]|[Bucket|RestBuckets]])
end.
-validate_doc_update(#db{}=Db, #doc{id= <<"_design/",_/binary>>}, _GetDiskDocFun) ->
- catch check_is_admin(Db);
+validate_doc_update(#db{}=Db, #doc{id= <<"_design/",_/binary>>}=Doc, _GetDiskDocFun) ->
+ case catch check_is_admin(Db) of
+ ok -> validate_ddoc(Db#db.name, Doc);
+ Error -> Error
+ end;
validate_doc_update(#db{validate_doc_funs = undefined} = Db, Doc, Fun) ->
ValidationFuns = load_validation_funs(Db),
validate_doc_update(Db#db{validate_doc_funs=ValidationFuns}, Doc, Fun);
@@ -519,6 +522,14 @@ validate_doc_update(Db, Doc, GetDiskDocFun) ->
validate_doc_update_int(Db, Doc, GetDiskDocFun)
end.
+validate_ddoc(DbName, DDoc) ->
+ try
+ couch_index_server:validate(DbName, couch_doc:with_ejson_body(DDoc))
+ catch
+ throw:Error ->
+ Error
+ end.
+
validate_doc_update_int(Db, Doc, GetDiskDocFun) ->
DiskDoc = GetDiskDocFun(),
JsonCtx = couch_util:json_user_ctx(Db),
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/22fdbe2e/src/couch_query_servers.erl
----------------------------------------------------------------------
diff --git a/src/couch_query_servers.erl b/src/couch_query_servers.erl
index d919a85..8e4130e 100644
--- a/src/couch_query_servers.erl
+++ b/src/couch_query_servers.erl
@@ -12,6 +12,7 @@
-module(couch_query_servers).
+-export([try_compile/4]).
-export([start_doc_map/3, map_docs/2, map_docs_raw/2, stop_doc_map/1, raw_to_ejson/1]).
-export([reduce/3, rereduce/3,validate_doc_update/5]).
-export([filter_docs/5]).
@@ -65,6 +66,17 @@
46,65,9,27,108,27,101,27,110,27,103,27,116,27,104,56,9,34,59,84,0,78,84,1,102,
65,9,27,125,56,9,84,1,206,0,0,0,0,0,0,0>>}).
+
+try_compile(Proc, FunctionType, FunctionName, FunctionSource) ->
+ try
+ proc_prompt(Proc, [<<"add_fun">>, FunctionSource]),
+ ok
+ catch {compilation_error, E} ->
+ Fmt = "Compilation of the ~s function in the '~s' view failed: ~s",
+ Msg = io_lib:format(Fmt, [FunctionType, FunctionName, E]),
+ throw({compilation_error, Msg})
+ end.
+
start_doc_map(Lang, Functions, Lib) ->
Proc = get_os_process(Lang),
case Lib of