Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem sending messages #3

Open
pgte opened this issue Sep 12, 2011 · 15 comments
Open

problem sending messages #3

pgte opened this issue Sep 12, 2011 · 15 comments

Comments

@pgte
Copy link

pgte commented Sep 12, 2011

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
Copy link
Author

pgte commented Sep 12, 2011

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 pgte closed this as completed Sep 12, 2011
@pgte pgte reopened this Sep 12, 2011
@pgte
Copy link
Author

pgte commented Sep 12, 2011

oops, closed by mistake, sorry. reopening.

@dscape
Copy link

dscape commented Sep 15, 2011

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

@dscape
Copy link

dscape commented Sep 15, 2011

Sorry @jhs :)

@jhs
Copy link
Owner

jhs commented Sep 16, 2011

@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!

@pgte
Copy link
Author

pgte commented Sep 16, 2011

@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

@jhs
Copy link
Owner

jhs commented Sep 16, 2011

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
Copy link
Owner

jhs commented Sep 16, 2011

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
Copy link
Owner

jhs commented Sep 16, 2011

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.

@pgte
Copy link
Author

pgte commented Sep 16, 2011

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.

@jhs
Copy link
Owner

jhs commented Sep 16, 2011

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.

@Nashorn
Copy link

Nashorn commented Sep 16, 2011

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:
#3 (comment)

@jhs
Copy link
Owner

jhs commented Sep 25, 2011

@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!

@pgte
Copy link
Author

pgte commented Sep 26, 2011

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!

@dscape
Copy link

dscape commented Sep 26, 2011

CouchBase will install cleanly and easy. Get the community edition

indexzero pushed a commit that referenced this issue Dec 8, 2014
Replaced log4js with debug, pass `require` to defaultable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants