Fork me on GitHub

Good day, How can I render resources from the db in the UI, I'm trying to create list-games and show-game functions, but I'm running into 500 "internal server errors". app.clj

(defn list-games [db]
  (let [games (xt/q db
                    '{:find [title]
                      :where [[_ :game/title title]]})]
                      [for game games]
                      [:h1 game])))

(defn show-game [db]
  (let [game (xt/q db
                    '{:find [id title]
                      :where [[e :game/title title]
                              [e :game/id id]]})]
                              [:h1 game])))
(def features
  {:routes ["/app"
            ["" {:get app}]
            ["/index/" {:get list-games}]
            ["/game/" {:get show-game}]]})

Jacob O'Bryant20:08:25

Whenever there's an internal server error, you can check the terminal. There should be an error message there with more information. What does it say?


Got it šŸ‘

[qtp1009357130-21] INFO com.biffweb.impl.middleware -   4ms 500 get  /app/index

Jacob O'Bryant21:08:41

is there a stack trace above that?


[qtp57305467-25] ERROR com.biffweb.impl.middleware - Exception while handling request
java.lang.IllegalArgumentException: No implementation of method: :q* of protocol: #'xtdb.api/PXtdbDatasource found for class: clojure.lang.PersistentHashMap
        at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584)
        at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:576)
        at xtdb.api$eval7763$fn__7820$G__7732__7829.invoke(api.clj:139)
        at xtdb.api$q.invokeStatic(api.clj:366)
        at xtdb.api$q.doInvoke(api.clj:360)
        at clojure.lang.RestFn.invoke(
        at $list_games.invokeStatic(app.clj:24)
        at $list_games.invoke(app.clj:23)
        at com.biffweb.impl.middleware$wrap_render_rum$fn__16091.invoke(middleware.clj:26)
        at com.biffweb.impl.middleware$wrap_anti_forgery_websockets$fn__16084.invoke(middleware.clj:22)
        at ring.middleware.anti_forgery$wrap_anti_forgery$fn__14646.invoke(anti_forgery.clj:94)
        at reitit.ring$ring_handler$fn__23128.invoke(ring.cljc:329)
        at clojure.lang.AFn.applyToHelper(
        at clojure.lang.AFn.applyTo(
        at clojure.lang.AFunction$1.doInvoke(
        at clojure.lang.RestFn.invoke(
        at muuntaja.middleware$wrap_params$fn__13829.invoke(middleware.clj:52)
        at muuntaja.middleware$wrap_format$fn__13833.invoke(middleware.clj:73)
        at com.biffweb.impl.middleware$wrap_resource$fn__16107.invoke(middleware.clj:49)  
        at com.biffweb.impl.middleware$wrap_internal_error$fn__16113.invoke(middleware.clj:55)
        at com.biffweb.impl.middleware$wrap_log_requests$fn__16118.invoke(middleware.clj:63)
        at clojure.lang.Var.invoke(
        at ring.middleware.flash$wrap_flash$fn__13949.invoke(flash.clj:39)
        at ring.middleware.session$wrap_session$fn__14380.invoke(session.clj:108)
        at ring.middleware.keyword_params$wrap_keyword_params$fn__14426.invoke(keyword_params.clj:53)
        at ring.middleware.nested_params$wrap_nested_params$fn__14484.invoke(nested_params.clj:89)
        at ring.middleware.multipart_params$wrap_multipart_params$fn__14782.invoke(multipart_params.clj:171)
        at ring.middleware.params$wrap_params$fn__14806.invoke(params.clj:67)
        at ring.middleware.cookies$wrap_cookies$fn__14259.invoke(cookies.clj:214)
        at ring.middleware.absolute_redirects$wrap_absolute_redirects$fn__14960.invoke(absolute_redirects.clj:47)
        at ring.middleware.content_type$wrap_content_type$fn__13881.invoke(content_type.clj:34)
        at ring.middleware.default_charset$wrap_default_charset$fn__14932.invoke(default_charset.clj:31)
        at ring.middleware.not_modified$wrap_not_modified$fn__14908.invoke(not_modified.clj:61)
        at ring.middleware.x_headers$wrap_x_header$fn__13912.invoke(x_headers.clj:22)     
        at ring.middleware.x_headers$wrap_x_header$fn__13912.invoke(x_headers.clj:22)     
        at ring.middleware.x_headers$wrap_x_header$fn__13912.invoke(x_headers.clj:22)     
        at com.biffweb.impl.middleware$wrap_env$fn__16137.invoke(middleware.clj:112)      
        at ring.adapter.jetty9$proxy_handler$fn__23619.invoke(jetty9.clj:75)
        at ring.adapter.jetty9.proxy$org.eclipse.jetty.servlet.ServletHandler$ff19274a.doHandle(Unknown Source)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(
        at org.eclipse.jetty.servlet.ServletHandler.doScope(      
        at ring.adapter.jetty9.proxy$org.eclipse.jetty.servlet.ServletHandler$ff19274a.doScope(Unknown Source)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(  
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
        at org.eclipse.jetty.server.Server.handle(
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(     
        at org.eclipse.jetty.server.HttpChannel.dispatch(
        at org.eclipse.jetty.server.HttpChannel.handle(
        at org.eclipse.jetty.server.HttpConnection.onFillable(    
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
        at org.eclipse.jetty.util.thread.QueuedThreadPool$
        at java.base/
[qtp57305467-25] INFO com.biffweb.impl.middleware -  10ms 500 get  /app/index/

Jacob O'Bryant22:08:14

java.lang.IllegalArgumentException: No implementation of method: :q* of protocol: #'xtdb.api/PXtdbDatasource found for class: clojure.lang.PersistentHashMap means you're trying to call the q function, but instead of passing it an XT database it's getting a map. I see the error now from the code you pasted earlier. The argument for list-games and show-game should be called sys or req, not db. You can get the db like so: (defn list-games [{:keys [biff/db] :as sys}] ...

šŸ™ 1
Jacob O'Bryant22:08:12

After that's fixed, there may be more errors--e.g. if you're using the default ui/page function, it needs to have a map as the first argument, like (ui/page {} [:h1 game]). Also the for in list-games has some incorrect syntax, see for some correct examples

šŸ™ 1

Thanks that cleared up a lot

šŸ‘Œ 1

The one thing I ran into, is a compilation error if I call list-games with :as sys e.g (defn list-games [{:keys [biff/db]] ...) works but (defn list-games [{:keys [biff/db] :as sys .. produces this error:

Syntax error macroexpanding clojure.core/defn at (com/game/feat/app.clj:24:1).
{:keys [biff/db]} - failed: vector? at: [:fn-tail :arity-n :bodies :params] spec: :clojure.core.specs.alpha/param-list
(:as sys) - failed: Extra input at: [:fn-tail :arity-1 :params] spec: :clojure.core.specs.alpha/param-list 
Same error if I replace sys with req

Jacob O'Bryant02:09:25

based on the error message, it looks like you had (defn list-games {:keys [biff/db]} ...). the parameter list needs to be wrapped with a vector, as in (defn list-games [{:keys [biff/db]}] ...)

šŸ™ 1
Jacob O'Bryant20:08:32

Just made some updates to Platypub's default theme: ā€¢ there's a new "Home logo image url" site option. If set, it'll display the image on the home page instead of the logo in the navbar. (It'll also get shown in other places where the subscribe form appears). ā€¢ If you add an "about" tag to one of your pages, then the home page will include an about section with the contents, and your author image/name/url. ā€¢ There's also additional metadata, so you can get a zipfile from and unzip it in themes/default/assets/, and it'll update the site icon for various apps/devices ā€¢ The posts listed on the home page are now split into two separate "featured" and "recent" sections ā€¢ There's a new page at https://<your website>/subscribe/ which has just a subscribe form. good for linking from other places where the reader has already been given context. For example:, Next up is migrating over to platypub... I'll probably add a new theme and call it "minimalist"