cqs icon indicating copy to clipboard operation
cqs copied to clipboard

problem sending messages

Open pgte opened this issue 14 years ago • 15 comments

I create a queue and all looks good. Here is the design doc source: https://gist.github.com/1211432

When sending a message I get a 500 response status from couchdb. In introduced some debugging at the request level and found that the error was {"error":"case_clause","reason":"{[{<<\"message\">>,<<\"/^CQS\\//.test is not a function\">>}

which comes from the validate_doc_update on the design doc, line 17:

... if(! /^CQS//.test(newDoc._id)) // A simple test, hopefully future-proof ...

BTW, I'm using cqs 0.3.0, node 0.4.10 and couchdn 1.1.0.

Thanks.

pgte avatar Sep 12 '11 15:09 pgte

Here is the trace from the couchdb log:

[error] [<0.13914.3>] Uncaught error in HTTP request: {error,
                                                   {case_clause,
                                                    {[{<<"message">>,
                                                       <<"/^CQS\\//.test is not a function">>},
                                                      {<<"fileName">>,
                                                       <<>>},
                                                      {<<"lineNumber">>,
                                                       17},
                                                      {<<"stack">>,
                                                       <<"([object Object],null,[object Object],[object Object])@:17\n(function (newDoc, oldDoc, userCtx, secObj) {var NAME = \"test1\";var my_msg_id = function (doc) {var for_me = /^CQS\\/test1\\/(.*)$/;var match = for_me.exec(doc._id);if (!match) {return null;}var msg_id = match[1];match = /^([0-9a-f]{32})($|\\/(.*)$)/.exec(msg_id);if (!match) {throw {forbidden: \"Invalid message id: \" + msg_id};}return {id: match[1], extra: match[3]};};if (!/^CQS\\//.test(newDoc._id)) {throw {forbidden: \"This database is for CQS only\"};}var msg_id = my_msg_id(newDoc);if (!msg_id) {return;}var good_keys = [\"_id\", \"_rev\", \"_revisions\", \"_deleted\", \"SenderId\", \"SentTimestamp\", \"visible_at\", \"ApproximateReceiveCount\", \"ApproximateFirstReceiveTimestamp\", \"MD5OfMessageBody\", \"Body\", \"ReceiverId\"];var key;for (key in newDoc) {if (good_keys.indexOf(key) === -1) {throw {forbidden: \"Invalid field: \" + key};}}if (newDoc._deleted) {if (oldDoc.ReceiverId !== userCtx.name) {throw {forbidden: \"You may not delete this document\"};}return;}if (!newDoc.visible_at) {throw {forbidden: \"Must set visible_at\"};}if (oldDoc) {if (newDoc.ReceiverId !== userCtx.name) {throw {forbidden: \"Must set ReceiverId to your name: \" + JSON.stringify(userCtx.name)};}} else {if (newDoc.SenderId !== userCtx.name) {throw {forbidden: \"Must set SenderId to your name: \" + JSON.stringify(userCtx.name)};}}},[object Object],[object Array])@/usr/local/Cellar/couchdb/1.1.0/share/couchdb/server/main.js:1211\n(\"_design/CQS/test1\",[object Array],[object Array])@/usr/local/Cellar/couchdb/1.1.0/share/couchdb/server/main.js:1431\n()@/usr/local/Cellar/couchdb/1.1.0/share/couchdb/server/main.js:1474\n@/usr/local/Cellar/couchdb/1.1.0/share/couchdb/server/main.js:1485\n">>}]}}}

pgte avatar Sep 12 '11 16:09 pgte

oops, closed by mistake, sorry. reopening.

pgte avatar Sep 12 '11 16:09 pgte

@JasonSmith : Any reason why you wouldn't take this pull request? It would be very useful for us :)

dscape avatar Sep 15 '11 12:09 dscape

Sorry @jhs :)

dscape avatar Sep 15 '11 12:09 dscape

@pgte and @dscape, sorry, I did not receive notifications. I will figure out how to fix that.

It looks like your Spidermonkey is a bit older than mine and does not have the RegExp .test() method. Would you please try the regexp branch and see if it works? Thanks!

jhs avatar Sep 16 '11 01:09 jhs

@jhs Thanks for the feedback! I tried merging the regexp branch into the master (so issue #4 would no trump me) and I got this error when posting a message: https://gist.github.com/db43bd54e28da5e2140d

pgte avatar Sep 16 '11 09:09 pgte

Are you running the unit test suite? I would like to see exactly which test fails to help identify the problem. I updated the documentation (and I made a mistake and had to git push --force, so be careful) to clarify how to run the tests.

Can you run the tests with your couch? Does it give any clues? If you have an Iris Couch account, does it behave any differently there?

Thanks!

jhs avatar Sep 16 '11 12:09 jhs

P.S. I believe the browser versions of the test have some errors, I will fix them before releasing another version but for now, the master branch only supports Node.

jhs avatar Sep 16 '11 12:09 jhs

Final note, I suppose the most likely thing is still regular expressions. Perhaps changing them to a string method instead?

// /^A-Z/.test(doc._id); // BAD
!! doc._id.match(/^A-Z/); // GOOD?

However I will wait for your feedback before changing the code again.

jhs avatar Sep 16 '11 12:09 jhs

Iriscouch works, but on my install fails. Strange, because it's a fresh homebrew install. Here is the couchdb trace: https://gist.github.com/5a6c04293375df68563f

Anyway, don't bother, I'll first try changing the ddoc as suggested.

pgte avatar Sep 16 '11 12:09 pgte

Ok, good idea. The only thing to check is that sometimes I needed the regex match results to extract substrings. That is why I like .test(), it is very clear to the programmer that we are asking (yes/no) if the string looks like X, not extracting substrings from it.

Good luck with the change, let me know if you have problems (I am also JasonSmith in #couchdb on Freenode), during daytime, US central.

jhs avatar Sep 16 '11 13:09 jhs

Hey, I am Jason Smith too. Not sure why I am on this list. Can someone remove me?

Thanks Jay

On Fri, Sep 16, 2011 at 9:07 AM, Jason Smith < [email protected]>wrote:

Ok, good idea. The only thing to check is that sometimes I needed the regex match results to extract substrings. That is why I like .test(), it is very clear to the programmer that we are asking (yes/no) if the string looks like X, not extracting substrings from it.

Good luck with the change, let me know if you have problems (I am also JasonSmith in #couchdb on Freenode), during daytime, US central.

Reply to this email directly or view it on GitHub: https://github.com/iriscouch/cqs/issues/3#issuecomment-2114542

Nashorn avatar Sep 16 '11 23:09 Nashorn

@pgte I think you are the first user of CQS on a non-Jason CouchDB build (i.e. not Iris Couch or build-couchdb). I am sorry that you encountered frustrating bugs. I was too careless writing with modern Javascript features that are not yet universal on the server-side.

Anyway, if I push a branch or two with some portability ports, are you able to test them? If so, I have some ideas to fix the bugs (mostly regular expression and possibly some Object.keys() calls and similar things.

Thanks very much for your help and your patience!

jhs avatar Sep 25 '11 22:09 jhs

Hi Jason, thanks for the feedback!

Meanwhile I have been distracted by other things, but I intend to revisit this, since it would be great to start using couchdb for everything, including message queueing. Personally I don't need to depend on older versions of couchdb for my project. I think it's just that the homebrew recipe is borked, so I'm trying one of Couchone official installs and get some feedback on it. Thanks again!

pgte avatar Sep 26 '11 08:09 pgte

CouchBase will install cleanly and easy. Get the community edition

dscape avatar Sep 26 '11 15:09 dscape