cloudant/bigcouch — Issue #84: error with validate_doc_update
Author: thelims
Created: 2011-12-01 00:52:41+00:00
State: open

Env: bigcouch 0.3.1
Issue: trying to insert a new doc (that has the validate_doc_update code)

* if we remove validate_doc_update from the design doc, then all works fine. All works fine on apache couchdb

This is console output of the error.

[Thu, 01 Dec 2011 00:37:34 GMT] [info] [<0.102.0>] [--------] couch_proc_manager <0.939.0> died {badarg,
[{erlang,port_command,
[#Port<0.2647>,
[91,
[34,<<"ddoc">>,34],
44,
[34,<<"new">>,34],
44,
[34,<<"_design/app">>,34],
44,
[123,
[34,<<"_id">>,34],
58,
[34,<<"_design/app">>,34],
44,
[34,<<"_rev">>,34],
58,
[34,
<<"1-f34b0e54d9b18462f921eff9329596cb">>,
34],
44,
[34,<<"language">>,34],
58,
[34,<<"javascript">>,34],
44,
[34,<<"views">>,34],
58,
[123,
[34,
<<"getOperatorDeviceCompatibilty">>,
34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get device compatibility data of an operator */\\r\\nfunction(doc) {\\r\\n\\tif(doc.docType == \\\"DEVICE_COMPATIBILITY\\\") {\\r\\n\\t\\temit(doc.operatorID, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getOperators">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of all Operators */\\nfunction(doc) {\\n\\tif(doc.docType == 'OPERATOR'){\\n\\t\\temit(null,doc);\\n\\t}\\n}\"",
125],
44,
[34,<<"isNameExist">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This view is to identify whether a document with particular name and type exist in cms database,\\n * Objective is to avoid duplication before creation, Key needs to be [\\\"name\\\",\\\"type\\\"] format.\\n */\\nfunction(doc) {\\n if(doc.name){\\n emit([doc.name,doc.docType]);\\n }\\n}\"",
125],
44,
[34,<<"getActiveIssuerOffers">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of offers by issuer id */\\r\\nfunction(doc){\\r\\n\\tif(doc.docType == 'OFFER' && doc.status == 'A'){\\r\\n\\t\\temit(doc.issuerID, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getIssuers">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of all issuers and issuers\\r\\n * from a particular date. To get issuers created after a particular date,\\r\\n * pass the unix time stamp of the date in the startkey parameter of the url.\\r\\n */\\r\\nfunction(doc){\\r\\n\\tif(doc.docType == 'ISSUER'){\\r\\n\\t\\temit(doc.createdAt, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getIssuerOffers">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of offers by issuer id */\\r\\nfunction(doc){\\r\\n\\tif(doc.docType == 'OFFER'){\\r\\n\\t\\temit(doc.issuerID, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getOperatorByCode">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the Operators by operator code*/\\nfunction(doc) {\\n\\tif(doc.docType == 'OPERATOR'){\\n\\t\\temit(doc.code,doc);\\n\\t}\\n}\"",
125],
44,
[34,
<<"getOperatorBlackListedPhoneNumbers">>,
34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This view is used to get BlackListed Phone Numbers by Operator*/\\r\\nfunction(doc) {\\r\\n\\tif(doc._id == 'blackListedPhoneNumbers') {\\r\\n\\t\\tfor(operator in doc.numbers) {\\r\\n\\t\\t\\temit(operator, doc.numbers[operator]);\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getActiveIssuers">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of all issuers and issuers\\r\\n * from a particular date. To get issuers created after a particular date,\\r\\n * pass the unix time stamp of the date in the startkey parameter of the url.\\r\\n */\\r\\nfunction(doc){\\r\\n\\tif(doc.docType == 'ISSUER' && doc.status == 'A'){\\r\\n\\t\\temit(doc.createdAt, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"getIssuerMetadata">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This view is used to get metadata of an issuer */\\r\\nfunction(doc) {\\r\\n\\tif(doc.docType == \\\"ISSUER_METADATA\\\") {\\r\\n\\t\\temit(doc.issuerID, doc);\\r\\n\\t}\\r\\n}\"",
125],
44,
[34,<<"isFileExists">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/*This view is used to check whether the issuer/operator has the same file \\r\\n * with same version.\\r\\n */\\r\\nfunction (doc) {\\r\\n if (doc.docType == 'ISSUER_METADATA' || doc.docType == 'DEVICE_COMPATIBILITY') {\\r\\n if (doc.docType == 'ISSUER_METADATA') {\\r\\n emit([doc.issuerID, doc.file.name, doc.version]);\\r\\n } else {\\r\\n emit([doc.operatorID, doc.file.name, doc.version]);\\r\\n }\\r\\n }\\r\\n}\"",
125],
44,
[34,<<"getActiveOperators">>,34],
58,
[123,
[34,<<"map">>,34],
58,
"\"/* This map view is used to get the list of all Operators */\\nfunction(doc) {\\n\\tif(doc.docType == 'OPERATOR' && doc.status == 'A'){\\n\\t\\temit(null,doc);\\n\\t}\\n}\"",
125],
125],
44,
[34,<<"validate_doc_update">>,34],
58,
"\"function(newDoc, savedDoc, userCtx) {\\n function require(test, msg) {\\n if(!test) {\\n throw({ forbidden: msg });\\n }\\n }\\n\\n // Only admins may delete docs.\\n if(newDoc._deleted) {\\n for(var i in userCtx.roles) {\\n if(userCtx.roles[i] === '_admin') {\\n //short circuit the rest of the validation\\n return;\\n }\\n }\\n\\n //because of the above short circuit, if we got this far then it's forbidden\\n throw({ forbidden: 'You are not allowed to delete docs.' });\\n }\\n\\n // Check fields that are immutable for all doc types.\\n if(savedDoc) {\\n require(newDoc.docType === savedDoc.docType, 'You cannot change docType.');\\n\\n require(newDoc.createdAt === savedDoc.createdAt, 'You cannot change createdAt.');\\n }\\n \\n // Check different fields for different docType values\\n switch(newDoc.docType) {\\n \\n\\tcase 'SE_OWNER':\\n\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name,\\n\\t\\t 'Name field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name.length <= 25,\\n\\t\\t 'Name field max length is 25'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.createdAt,\\n\\t\\t 'CreatedAt field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status,\\n\\t\\t 'Status field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status.length === 1,\\n\\t\\t 'Status field max length is 1'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status == 'A' || newDoc.status == 'P',\\n\\t\\t 'SEowner Status should be A || P'\\n\\t\\t);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\n\\tcase 'ISSUER':\\n\\t\\n\\t\\trequire(\\n\\t\\t newDoc.code,\\n\\t\\t 'Issuer Code field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.code.length <= 12,\\n\\t\\t 'Issuer Code max size 12 '\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.type,\\n\\t\\t 'Issuer Type field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.type.length <= 8,\\n\\t\\t 'Issuer Type max size 8'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name,\\n\\t\\t 'Name field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name.length <= 25,\\n\\t\\t 'Name field max length is 25'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.createdAt,\\n\\t\\t 'CreatedAt field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status,\\n\\t\\t 'Status field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status.length === 1,\\n\\t\\t 'Status field max length is 1'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status == 'A' || newDoc.status == 'P' || newDoc.status == 'I',\\n\\t\\t 'Status should be A || P || I'\\n\\t\\t);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\t\\n\\tcase 'OFFER':\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.type,\\n\\t\\t 'Type field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.type.length <= 12,\\n\\t\\t 'Type field max length is 12'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name,\\n\\t\\t 'Name field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name.length <= 25,\\n\\t\\t 'Name field max length is 25'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.hasCoupon !== undefined,\\n\\t\\t 'HasCoupon field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t (newDoc.hasCoupon === true || newDoc.hasCoupon === false),\\n\\t\\t 'HasCoupon field should be Boolean'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.maxRedemptions,\\n\\t\\t 'MaxRedemptions field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.startsAt,\\n\\t\\t 'StartsAt field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\t//require(\\n\\t\\t //newDoc.endsAt,\\n\\t\\t //'EndsAt field required'\\n\\t\\t//);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.state,\\n\\t\\t 'Offer State field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.state.length <= 16,\\n\\t\\t 'Offer State field max length is 16'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.createdAt,\\n\\t\\t 'CreatedAt field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status,\\n\\t\\t 'Status field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status.length === 1,\\n\\t\\t 'Status field max length is 1'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status == 'A' || newDoc.status == 'P' || newDoc.status == 'I',\\n\\t\\t 'Status should be A || P || I'\\n\\t\\t);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\t\\n\\tcase 'OPERATOR':\\n\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name,\\n\\t\\t 'Name field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.name.length <= 25,\\n\\t\\t 'Name field max length is 25'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.code,\\n\\t\\t 'Code field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.createdAt,\\n\\t\\t 'CreatedAt field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status,\\n\\t\\t 'Status field required'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status.length === 1,\\n\\t\\t 'Status field max length is 1'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.status == 'A' || newDoc.status == 'P' || newDoc.status == 'I',\\n\\t\\t 'Status should be A || P || I'\\n\\t\\t);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\t\\n\\tcase 'ISSUER_METADATA':\\n\\t\\n\\t\\trequire(\\n\\t\\t newDoc.issuerID,\\n\\t\\t 'IssuerID field is required for issuer metadata'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.file.name,\\n\\t\\t 'FileName is requried for issuer metadata'\\n\\t\\t);\\n\\t\\t\\n\\t\\t//require(\\n\\t\\t //newDoc.fileContent.length <= 4194304,\\n\\t\\t //'Filesize should be not be greater than 4MB'\\n\\t\\t//);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\t\\n\\tcase 'DEVICE_COMPATIBILITY':\\n\\t\\n\\t\\trequire(\\n\\t\\t newDoc.operatorID,\\n\\t\\t 'OperatorID field is required for device compatibility'\\n\\t\\t);\\n\\t\\t\\n\\t\\trequire(\\n\\t\\t newDoc.file.name,\\n\\t\\t 'FileName is requried for device compatibility'\\n\\t\\t);\\n\\t\\t\\n\\t\\t//require(\\n\\t\\t //newDoc.fileContent.length <= 4194304,\\n\\t\\t //'Filesize should be not be greater than 4MB'\\n\\t\\t//);\\n\\t\\t\\n\\t\\tbreak;\\n\\t\\n\\tdefault:\\n if(newDoc._id != 'listOfSEIDs' && newDoc._id != 'walletTOU' && newDoc._id != 'blackListedPhoneNumbers'){\\n\\t throw({ forbidden: 'You must provide a valid docType.' });\\n\\t }\\n break;\\n }\\n \\n}\"",
44,
[34,<<"couchapp">>,34],
58,
[123,
[34,<<"signatures">>,34],
58,<<"{}">>,44,
[34,<<"objects">>,34],
58,<<"{}">>,44,
[34,<<"manifest">>,34],
58,
[91,
[34,<<"language">>,34],
44,
[34,<<"views/">>,34],
44,
[34,
<<"views/getOperatorBlackListedPhoneNumbers/">>,
34],
44,
[34,
<<"views/getOperatorBlackListedPhoneNumbers/map.js">>,
34],
44,
[34,<<"views/getActiveIssuers/">>,
34],
44,
[34,
<<"views/getActiveIssuers/map.js">>,
34],
44,
[34,<<"views/getActiveOperators/">>,
34],
44,
[34,
<<"views/getActiveOperators/map.js">>,
34],
44,
[34,<<"views/getIssuerMetadata/">>,
34],
44,
[34,
<<"views/getIssuerMetadata/map.js">>,
34],
44,
[34,<<"views/isFileExists/">>,34],
44,
[34,<<"views/isFileExists/map.js">>,
34],
44,
[34,<<"views/isNameExist/">>,34],
44,
[34,<<"views/isNameExist/map.js">>,
34],
44,
[34,
<<"views/getActiveIssuerOffers/">>,
34],
44,
[34,
<<"views/getActiveIssuerOffers/map.js">>,
34],
44,
[34,<<"views/getIssuerOffers/">>,34],
44,
[34,
<<"views/getIssuerOffers/map.js">>,
34],
44,
[34,<<"views/getIssuers/">>,34],
44,
[34,<<"views/getIssuers/map.js">>,
34],
44,
[34,<<"views/getOperatorByCode/">>,
34],
44,
[34,
<<"views/getOperatorByCode/map.js">>,
34],
44,
[34,<<"views/getOperators/">>,34],
44,
[34,<<"views/getOperators/map.js">>,
34],
44,
[34,
<<"views/getOperatorDeviceCompatibilty/">>,
34],
44,
[34,
<<"views/getOperatorDeviceCompatibilty/map.js">>,
34],
44,
[34,<<"validate_doc_update">>,34],
93],
125],
125],
93,10]]},
{couch_os_process,writeline,2},
{couch_os_process,writejson,2},
{couch_os_process,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}