clojure/compojure/hiccup NullPointerException
我的堆栈跟踪不包含对我的代码的任何引用。我不知道如何开始找出这里可能出现的问题:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是我的路由定义看起来像这样:
我需要将参数传递给创建提交调用。因为create-submit参数的定义是
[& m]
我猜它没有抱怨参数数量错误。更正:
而且 model/create 方法也会抛出异常,因为我没有添加对 db.clj 文件的需求,这是我进行
cql/open-global
调用的地方。堆栈跟踪完全不明显——我希望它指向 cql/conj 下的某个位置!它试图建立连接的地方。相反,它指向打嗝,这根本没有意义。
Well the reason was that my route definition looked something like this:
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.