clutch working on local couchdb; fails on cloudant

124 views
Skip to first unread message

Walter Babic

unread,
Jun 21, 2012, 2:14:38 AM6/21/12
to clojure...@googlegroups.com
Hello,
I am working with clutch:
[com.ashafa/clutch "0.4.0-SNAPSHOT"]

and a local version of couchDB and a version on Cloudant.

Same code works locally but not with Cloudant:

ts.core=> (get-docs local-db {:keys [wb]})
({:id "b6e...88b", :key "wb*@*.com", :value {:_id "b6e...88b", :_rev "13-f9...09", ... , :email "wb*@*.com"}})

ts.core=> (get-docs prod-db {:keys [wb]})
ExceptionInfo clj-http: status 500  clj-http.client/wrap-exceptions/fn--946 (client.clj:86) 

where 

ts.core=> local-db
#cemerick.url.URL{:protocol "http", :username "wbabic", :password "*******", :host "localhost", :port 5984, :path "/ts", :query nil, :anchor nil}
ts.core=> prod-db
#cemerick.url.URL{:protocol "http", :username "wbabic", :password "********", :host "wbabic.cloudant.com", :port 80, :path "/travelingsirens", :query nil, :anchor nil}

(defn get-docs
  [db keys]
  (clutch/with-db db (clutch/get-view "profile" "email" keys)))

and

ts.core=> wb
"wb*@*.com"

prod-db url seem correct since get-database works:

ts.core=> (get-database local-db)
#cemerick.url.URL{:protocol "http", :username "wbabic", :password "********", :host "localhost", :port 5984, :path "/ts", :query nil, ... :doc_count 3}
ts.core=> (get-database prod-db)
#cemerick.url.URL{:protocol "http", :username "wbabic", :password "********", :host "wbabic.cloudant.com", :port 80, :path "/travelingsirens", :query nil,.... :doc_count 4}


(defn get-database [db]
  (clutch/get-database db))


Any reasons why it does not work on Cloudant? Any ideas on how to see whats going on?


Thanks,
Walter

Michael Gorsuch

unread,
Jun 21, 2012, 6:53:37 AM6/21/12
to clojure...@googlegroups.com
On Thu, Jun 21, 2012 at 1:14 AM, Walter Babic <wba...@gmail.com> wrote:
> Any reasons why it does not work on Cloudant? Any ideas on how to see whats
> going on?

Hi Walter - I was trying to reason through some of this and noticed
that you didn't post any info on the view definition. Any chance you
can do that? Have you verified that it exists on Cloudant and can be
accessed / queried via other means?

Best,

Michael

Walter Babic

unread,
Jun 21, 2012, 2:46:47 PM6/21/12
to clojure...@googlegroups.com
Yes, thanks, Michael,  good suggestion.

Here is what I found using cURL:

bash-3.2$  curl -X GET http://wbabic:********@localhost:5984/ts/_design/profile/_view/email
{"total_rows":2,"offset":0,"rows":[
  data looks right
]}


bash-3.2$  curl -X GET http://wbabic:********@wbabic.cloudant.com/travelingsirens/_design/profile/_view/email
{"error":"compilation_error","reason":"Expression does not eval to a function. ((new String(\"(function () {function b(a){throw 

I will try reloading the view. 

Thanks,
Walter

Walter Babic

unread,
Jun 21, 2012, 3:18:24 PM6/21/12
to clojure...@googlegroups.com
Here is the view, which was working, I thought anyway. After reloading locally, I get the same error. Consistent, at least. It has been a while since I had first loaded the view locally and has been working since, until I just reloaded. Broken in dev, I can deal with. Working in dev but not prod is harder. So does the view look okay? 

;;; create view by email
(defn add-view
  [db]
  (clutch/with-db db
    (clutch/save-view
     "profile"
     (clutch/view-server-fns
      :cljs
      {:email
       {:map (fn [doc]
               (js/emit (aget doc "email") doc))}}))))

ts.core=> (add-view local-db)
{:_id "_design/profile", :_rev "2-4a43ac7535742ac39ee80f59f90ce56b", :views {:email {:map "(function () {function b(a){throw a;}var f=!0,h=null,k=!1;function aa(){return function(a){return a}}function l(a){return function(){return this[a]}}function m(a){return function(){return a}}var p;\nfunction q(a){var c=typeof a;if(\"object\"==c)if(a){if(a instanceof Array)return\"array\";if(a instanceof Object)return c;var d=Object.prototype.toString.call(a);if(\"[object W


ts.core=> (add-view prod-db)
{:_id "_design/profile", :_rev "2-6b90109a01d29e69eac6f1b170ace84f", :views {:email {:map "(function () {function b(a){throw a;}var f=!0,h=null,k=!1;function aa(){return function(a){return a}}function l(a){return function(){return this[a]}}function m(a){return function(){return a}}var p;\nfunction q(a){var c=typeof a;if(\"object\"==c)if(a){if(a instanceof Array)return\"array\";if(a instanceof Object)return c;var d=Object.prototype.toString.call(a);if(\"[object Window]\"==d)return\"object\";if(\"[object Array]\"==d||\"number\"==typeof a.length&&\"undefined\"!=typeof a.splice&&\"und ....


bash-3.2$  curl -X GET http://wbabic:********@localhost:5984/ts/_design/profile/_view/email
{"error":"compilation_error","reason":"Expression does not eval to a function. ((new String(\"(function () {function b(a){throw 

bash-3.2$  curl -X GET http://wbabic:********@wbabic.cloudant.com/travelingsirens/_design/profile/_view/email
{"error":"compilation_error","reason":"Expression does not eval to a function. ((new String(\"(function () {function b(a){throw 

Sam Ritchie

unread,
Jun 21, 2012, 4:36:31 PM6/21/12
to clojure...@googlegroups.com
Walter, you don't happen to have any AOT compilation in your project, do you? If you accidentally AOT compile the clojurescript compiler view creation will break. To fix this, I had to to add :skip-aot metadata to my :main entry in project.clj. For example,

:main ^{:skip-aot true} paddleguru.server

Hope that helps,
Sam
--
Sam Ritchie, Twitter Inc
@sritchie09

(Too brief? Here's why! http://emailcharter.org)

Walter Babic

unread,
Jun 21, 2012, 5:04:29 PM6/21/12
to clojure...@googlegroups.com
I added 

                 [org.clojure/clojurescript "0.0-1011" :optional true
                  :exclusions [com.google.code.findbugs/jsr305
                               com.googlecode.jarjar/jarjar
                               junit
                               org.apache.ant/ant
                               org.json/json
                               org.mozilla/rhino]]

the exclusions, as in clutch/project.clj and now it works.
Previously, I only had 

                 [org.clojure/clojurescript "0.0-1011"]

So it works now, although I am not totally sure why,
thanks for the help.

Walter

On Thursday, June 21, 2012 12:14:38 AM UTC-6, Walter Babic wrote:

Chas Emerick

unread,
Jun 21, 2012, 10:48:41 PM6/21/12
to clojure...@googlegroups.com
Hi Walter,

Sorry for the difficulties you ran into.  The exclusions in the clutch project shouldn't be required for cljs views to be compiled properly, though.  The fact that they worked well locally (presumably with the exclusion-less cljs dependency) would seem to confirm that in your case.

The broken view code you pasted is woefully incomplete.  A cljs view is likely to be ~40K or more, not just a few lines of JavaScript.  I'm thinking that the Closure compiler wasn't able to find the base ClojureScript files, leading to the incomplete result.  IIRC, I've had the same problem in one or two circumstances; clearing the 'out' directory (a temporary work space for the ClojureScript and Closure compilers) has resolved the problem.  If you can try doing this with the exclusion-less cljs dependency, that'd be great.

Thanks,

- Chas

--
http://cemerick.com
[Clojure Programming from O'Reilly](http://www.clojurebook.com)

Walter Babic

unread,
Jun 22, 2012, 12:56:23 PM6/22/12
to clojure...@googlegroups.com
Chas,

I tried again with no exclusions in the cljs dependency: [org.clojure/clojurescript "0.0-1011"] and it worked both locally and on Cloudant. 

Thanks,
Walter.

Walter Babic

unread,
Jun 22, 2012, 1:09:20 PM6/22/12
to clojure...@googlegroups.com
The broken view code you pasted is woefully incomplete. 

Yes, that was just a proof of concept. I have just started ch 15 of Clojure Programming. Looks like there os some good stuff there. I have been enjoying the book so far, thanks for making that available.

-Walter

Chas Emerick

unread,
Jun 22, 2012, 1:49:10 PM6/22/12
to clojure...@googlegroups.com
On Jun 22, 2012, at 1:09 PM, Walter Babic wrote:

The broken view code you pasted is woefully incomplete. 

Yes, that was just a proof of concept. I have just started ch 15 of Clojure Programming. Looks like there os some good stuff there. I have been enjoying the book so far, thanks for making that available.

Sorry, that wasn't clear. :-)

I wasn't saying that you had missed anything; I was saying that the JavaScript that results from (what should be) automatic core.cljs compilation didn't appear to be in the generated code.

Glad you're liking the book, though!

- Chas
Reply all
Reply to author
Forward
0 new messages