clojure/compojure/hiccup NullPointerException

发布于 2024-12-02 07:48:50 字数 2315 浏览 0 评论 0原文

我的堆栈跟踪不包含对我的代码的任何引用。我不知道如何开始找出这里可能出现的问题:

LazySeq.java:47 clojure.lang.LazySeq.sval
LazySeq.java:56 clojure.lang.LazySeq.seq
Cons.java:39    clojure.lang.Cons.next
RT.java:560 clojure.lang.RT.next
core.clj:61 clojure.core/next
core.clj:461    clojure.core/str$fn[fn]
core.clj:463    clojure.core/str
RestFn.java:140 clojure.lang.RestFn.applyTo
core.clj:540    clojure.core/apply
core.clj:90 hiccup.core/eval460$fn[fn]
MultiFn.java:163    clojure.lang.MultiFn.invoke
Var.java:365    clojure.lang.Var.invoke
stacktrace.clj:26   ring.middleware.stacktrace/html-ex-view
stacktrace.clj:40   ring.middleware.stacktrace/html-ex-response
stacktrace.clj:51   ring.middleware.stacktrace/ex-response
stacktrace.clj:61   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
reload_modified.clj:15  ring.middleware.reload-modified/wrap-reload-modified$fn[fn]
stacktrace.clj:59   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
jetty.clj:17    ring.adapter.jetty/proxy-handler$fn[fn]
(Unknown Source)        ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle
HandlerWrapper.java:152 org.mortbay.jetty.handler.HandlerWrapper.handle
Server.java:324 org.mortbay.jetty.Server.handle
HttpConnection.java:534 org.mortbay.jetty.HttpConnection.handleRequest
HttpConnection.java:879 org.mortbay.jetty.HttpConnection$RequestHandler.content
HttpParser.java:741 org.mortbay.jetty.HttpParser.parseNext
HttpParser.java:213 org.mortbay.jetty.HttpParser.parseAvailable
HttpConnection.java:403 org.mortbay.jetty.HttpConnection.handle
SocketConnector.java:228    org.mortbay.jetty.bio.SocketConnector$Connection.run
QueuedThreadPool.java:522   org.mortbay.thread.QueuedThreadPool$PoolThread.run

这种情况发生在表单提交之后 - 控制器将记录写入数据库并重定向到页面:

(defn create-submit [& m]
  (let [p (model/create m)]
      (response/redirect (str "/post/" (:id p)))))

我在堆栈跟踪中看到打嗝,但没有页面渲染正在进行中。而且浏览器仍然指向原始页面,而不是重定向的页面,所以我认为重定向永远不会发生。

有想法吗?

编辑:

通过一些 println,我将其跟踪到模型/创建调用,该调用正在调用 clojureql 来 conj!新纪录。第一个 println 显示在控制台窗口中,而第二个则没有。

(defn create [m] 
    (let [p (new-post-from m)] 
        (println "about to add p to table " (:id p)) 
        (cql/conj! (cql/table :posts) p)
        (println "after adding p to table")
    p)) 

The stack trace I have does not contain any reference to my code. I'm not sure how to begin finding out what might be wrong here:

LazySeq.java:47 clojure.lang.LazySeq.sval
LazySeq.java:56 clojure.lang.LazySeq.seq
Cons.java:39    clojure.lang.Cons.next
RT.java:560 clojure.lang.RT.next
core.clj:61 clojure.core/next
core.clj:461    clojure.core/str$fn[fn]
core.clj:463    clojure.core/str
RestFn.java:140 clojure.lang.RestFn.applyTo
core.clj:540    clojure.core/apply
core.clj:90 hiccup.core/eval460$fn[fn]
MultiFn.java:163    clojure.lang.MultiFn.invoke
Var.java:365    clojure.lang.Var.invoke
stacktrace.clj:26   ring.middleware.stacktrace/html-ex-view
stacktrace.clj:40   ring.middleware.stacktrace/html-ex-response
stacktrace.clj:51   ring.middleware.stacktrace/ex-response
stacktrace.clj:61   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
reload_modified.clj:15  ring.middleware.reload-modified/wrap-reload-modified$fn[fn]
stacktrace.clj:59   ring.middleware.stacktrace/wrap-stacktrace$fn[fn]
jetty.clj:17    ring.adapter.jetty/proxy-handler$fn[fn]
(Unknown Source)        ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle
HandlerWrapper.java:152 org.mortbay.jetty.handler.HandlerWrapper.handle
Server.java:324 org.mortbay.jetty.Server.handle
HttpConnection.java:534 org.mortbay.jetty.HttpConnection.handleRequest
HttpConnection.java:879 org.mortbay.jetty.HttpConnection$RequestHandler.content
HttpParser.java:741 org.mortbay.jetty.HttpParser.parseNext
HttpParser.java:213 org.mortbay.jetty.HttpParser.parseAvailable
HttpConnection.java:403 org.mortbay.jetty.HttpConnection.handle
SocketConnector.java:228    org.mortbay.jetty.bio.SocketConnector$Connection.run
QueuedThreadPool.java:522   org.mortbay.thread.QueuedThreadPool$PoolThread.run

This happens after a form submit--the controller writes a record to the db and redirects to the page:

(defn create-submit [& m]
  (let [p (model/create m)]
      (response/redirect (str "/post/" (:id p)))))

I see hiccup in the stack trace but there is no page rendering going on here. And the browser still points to the original page, not the redirected page, so I'm thinking that the redirect never happens.

Ideas?

EDIT:

With some println's I've tracked it down to the model/create call, which is calling clojureql to conj! the new record. The first println shows up in the console window and the second doesn't.

(defn create [m] 
    (let [p (new-post-from m)] 
        (println "about to add p to table " (:id p)) 
        (cql/conj! (cql/table :posts) p)
        (println "after adding p to table")
    p)) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2024-12-09 07:48:50

原因是我的路由定义看起来像这样:

(POST "/post/create/submit" (params :params) (post/create-submit))

我需要将参数传递给创建提交​​调用。因为create-submit参数的定义是[& m] 我猜它没有抱怨参数数量错误。

更正:
而且 model/create 方法也会抛出异常,因为我没有添加对 db.clj 文件的需求,这是我进行 cql/open-global 调用的地方。

堆栈跟踪完全不明显——我希望它指向 cql/conj 下的某个位置!它试图建立连接的地方。相反,它指向打嗝,这根本没有意义。

Well the reason was that my route definition looked something like this:

(POST "/post/create/submit" (params :params) (post/create-submit))

Where I was needing to passing params to the create-submit call. Because the definition of create-submit parameters was [& m] I guess it didn't complain about wrong number of parameters.

CORRECTION:
And also the model/create method was throwing because I had not added a require for the db.clj file, which is where I had my cql/open-global call.

The stack trace was completely non-obvious--I would expect it to point to some place under cql/conj! where it's trying to establish a connection. Instead it was pointing to hiccup which makes no sense at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文