Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.9.1, 0.10
-
None
-
New Contributors Level (Easy)
Description
For example, if I create validate_doc_update:
function (oldDoc, newDoc, userCtx) {
doc.foo;
}
I am greeted by an "OS process timed out" message. In the logs, all I see is:
OS Process :: Error converting object to JSON: TypeError: {Array:function (v) {var buf = [];for (var i = 0; i < v.length; i++)
{buf.push(toJSON(v[i]));}return "[" + buf.join(",") + "]";}, Boolean:function (v)
{return v.toString();}, Date:function (v) {var f = function
{return n < 10 ? "0" + n : n;};return "\"" + v.getUTCFullYear() + "" + f(v.getUTCMonth() + 1) + "" + f(v.getUTCDate()) + "T" + f(v.getUTCHours()) + ":" + f(v.getUTCMinutes()) + ":" + f(v.getUTCSeconds()) + "Z\"";}, Number:function (v)
, Object:function (v) {if (v === null)
{return "null";}var buf = [];for (var k in v) {if (!v.hasOwnProperty(k) || typeof k !== "string" || v[k] === undefined)
{continue;}buf.push(toJSON(k, val) + ": " + toJSON(v[k]));}return "
{" + buf.join(",") + "}";}, String:function (v) {if (/["\\\x00-\x1f]/.test(v)) {v = v.replace(/([\x00-\x1f\\"])/g, function (a, b) {var c = subs[b];if (c)
{return c;}c = b.charCodeAt();return "
u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16);});}return "\"" + v + "\"";}}[val != null ? val.constructor.name : "Object"] is not a function
When really the problem is a ReferenceError (I should have used newDoc.foo or oldDoc.foo). The attached patch modifies toJSON() in utils.js so that it converts anything that isn't a String, Array, Date, Object etc. into a String. This makes the error appear in the popup in Futon when saving.
This isn't necessarily the best thing to do as it modifies the semantics of toJSON(), and also we might want to keep the exception info in the logs, and not propagate it to the user. Perhaps it would be better to modify respond(obj) to produce a better error message in the logs (simply adding something that tried to log obj.toString() would suffice).
Attachments
Attachments
Issue Links
- is part of
-
COUCHDB-111 Javascript Error Tracebacks
- Closed
- is related to
-
COUCHDB-484 validate_doc_update returns an HTTP 500 if validation fails
- Closed
- is superceded by
-
COUCHDB-111 Javascript Error Tracebacks
- Closed