plumatic / fnhouse

Eclipse Public License 1.0
220 stars 28 forks source link

Non-informative error when handler returns nil #20

Open si14 opened 9 years ago

si14 commented 9 years ago

It's a common pattern for Ring handlers to return nil. However, when this is the case, coercion-middleware explodes with non-informative message:

java.lang.NullPointerException
    at fnhouse.middleware$response_walker$fn__5341.invoke(middleware.clj:90)
    at fnhouse.middleware$eval5351$coercion_middleware__5352$fn__5356$fn__5358.invoke(middleware.clj:113)
    at fnhouse.routes$eval4736$root_handler__4737$fn__4738$fnk4739__4745$fn__4746.invoke(routes.clj:131)
    at fnhouse.routes$eval4736$root_handler__4737$fn__4738$fnk4739__4745.invoke(routes.clj:128)
    at clojure.lang.AFn.applyToHelper(AFn.java:154)
    at clojure.lang.AFn.applyTo(AFn.java:144)
    at clojure.lang.AFunction$1.doInvoke(AFunction.java:29)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
...

It happens when anonymous function in response-walker gets nil for response. I don't know what would be better: to give more informative message there or to skip output coercion, assuming that there is an or somewhere upstream and other handler will be called or 404 will be raised.

Which approach is better and should I make a PR with fix?

w01fe commented 9 years ago

Thanks for the report.

For now, fnhouse is structured so that the handler must always be uniquely determined by the route, so I'm not sure passing the nil through is the right thing (but very open to discussing options). The simplest option for now seems to be to make the error message better, for which a PR would definitely be welcome.

Thanks again!