diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2013-03-10 16:03:00 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2013-03-20 06:02:54 -0500 |
commit | b474248c6fd7f2bb5bab20225869920d87414ea7 (patch) | |
tree | eea717734ce0c9622ce6bfeb62e0db1be21d602e /src/couch_index | |
parent | 0861ab00177223afdaeb10d329ab2daa79cb053e (diff) | |
download | couchdb-b474248c6fd7f2bb5bab20225869920d87414ea7.tar.gz |
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.
Diffstat (limited to 'src/couch_index')
-rw-r--r-- | src/couch_index/src/couch_index_server.erl | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl index a106f14e1..3d8a797f0 100644 --- a/src/couch_index/src/couch_index_server.erl +++ b/src/couch_index/src/couch_index_server.erl @@ -14,7 +14,7 @@ -behaviour(gen_server). -behaviour(config_listener). --export([start_link/0, get_index/4, get_index/3, get_index/2]). +-export([start_link/0, validate/2, get_index/4, get_index/3, get_index/2]). -export([update_notify/1]). -export([init/1, terminate/2, code_change/3]). @@ -35,6 +35,32 @@ start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + +validate(DbName, DDoc) -> + LoadModFun = fun + ({ModNameList, "true"}) -> + try + [list_to_existing_atom(ModNameList)] + catch error:badarg -> + [] + end; + ({_ModNameList, _Enabled}) -> + [] + end, + ValidateFun = fun + (ModName, ok) -> + try + ModName:validate(DbName, DDoc) + catch Type:Reason -> + {Type, Reason} + end; + (_ModName, Error) -> + Error + end, + EnabledIndexers = lists:flatmap(LoadModFun, config:get("indexers")), + lists:foldl(ValidateFun, ok, EnabledIndexers). + + get_index(Module, <<"shards/", _/binary>>=DbName, DDoc) -> {Pid, Ref} = spawn_monitor(fun() -> exit(fabric:open_doc(mem3:dbname(DbName), DDoc, [])) |