couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Noah Slater (JIRA)" <j...@apache.org>
Subject [jira] Updated: (COUCHDB-410) JavaScript errors in validate_doc_update should be handled more gracefully
Date Mon, 29 Mar 2010 15:52:28 GMT

     [ https://issues.apache.org/jira/browse/COUCHDB-410?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Noah Slater updated COUCHDB-410:
--------------------------------

    Fix Version/s:     (was: 0.11)
                   0.12

> JavaScript errors in validate_doc_update should be handled more gracefully
> --------------------------------------------------------------------------
>
>                 Key: COUCHDB-410
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-410
>             Project: CouchDB
>          Issue Type: Bug
>          Components: Database Core
>    Affects Versions: 0.9.1, 0.10
>            Reporter: Jason Davies
>             Fix For: 0.12
>
>         Attachments: util.js.diff
>
>
> 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
(n) {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) {return isFinite(v) ? v.toString() :
"null";}, 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).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message