Swirrl / drafter

A clojure service and a client to it for exposing data management operations to PMD
Other
0 stars 0 forks source link

updating a draft with cat.gif causes the job status endpoint to 500 #14

Closed asacalow closed 9 years ago

asacalow commented 9 years ago

Stacktrace below. Was expecting a 200 with a JSON body containing the error.

com.fasterxml.jackson.core.JsonGenerationException
Cannot JSON encode object of class: class java.lang.NullPointerException: java.lang.NullPointerException
generate.clj:147    cheshire.generate/generate
generate.clj:119    cheshire.generate/generate
core.clj:32 cheshire.core/generate-string
core.clj:19 cheshire.core/generate-string
format_response.clj:118 ring.middleware.format-response/wrap-format-response[fn]
multipart_params.clj:118    ring.middleware.multipart-params/wrap-multipart-params[fn]
validation.clj:155  noir.validation/wrap-noir-validation[fn]
cookies.clj:72  noir.cookies/noir-cookies[fn]
cookies.clj:156 ring.middleware.cookies/wrap-cookies[fn]
session.clj:148 noir.session/noir-flash[fn]
flash.clj:35    ring.middleware.flash/wrap-flash[fn]
session.clj:99  noir.session/noir-session[fn]
session.clj:98  ring.middleware.session/wrap-session[fn]
Var.java:379    clojure.lang.Var.invoke
resource.clj:25 ring.middleware.resource/wrap-resource[fn]
file_info.clj:69    ring.middleware.file-info/wrap-file-info[fn]
reload.clj:22   ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:23   ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:86   ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:20    ring.adapter.jetty/proxy-handler[fn]
(Unknown Source)    ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:369 org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:486 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:933 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:995 org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:644 org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235 org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:668  org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52   org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608   org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543   org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:744 java.lang.Thread.run
RickMoynihan commented 9 years ago

This is a bug - but should have a relatively striaghtforward fix.

Basically we just need to add a custom JSON serialiser for java exceptions to cheshire; our JSON parser/generator.

I'd suggest something along the lines of:

{:type :exception
 :class "java.lang.NullPointerException"
 :message "You broke stuff"
 :stacktrace ["draft-management.clj    drafter.rdf.draft-manangement/make-live:35" "flash.clj:35    ring.middleware.flash/wrap-flash[fn]"]
}

In some circumstances we may want to surface the stacktrace... e.g. when using the grafter import service... In others we probably don't want to...

@lkitching It would be :top: if you could :nut_and_bolt: this one together for me. It's on the async branch, and should be pretty simple. Ask mr @asacalow for details on how to recreate if you're unsure...

Basically Asa submits a request to add data to a draft... and then polls /status/:job-id till the task is done... Done tasks are ones that have their promise delivered, and the promise contains a datastructure which then contains the Exception, or a success message.

Failed jobs are still counted as finished jobs.

Asa wants the error back with a 200 response, but cheshire can't yet serialise java exceptions... so :boom: server 500!