noir-clojure / lib-noir

A set of libraries for ring apps, including stateful sessions.
Eclipse Public License 1.0
483 stars 47 forks source link

noir in-browser stack traces #102

Closed ccfontes closed 10 years ago

ccfontes commented 10 years ago

Wouldn't it be cool to include those pretty stack traces? They are so useful, specially to visualize lines that belong to the project namespaces.

screen shot 2014-06-14 at 20 54 07

yogthos commented 10 years ago

I don't think lib-noir would be the right place to add this feature. The exception handling is tied in with the Noir server code and checks whether the dev flag is set or not when rendering exceptions. Following that model it would make more sense to add this wrapper to Luminus instead.

Also, note that Ring already pretty prints exception stacktraces in dev mode.

ccfontes commented 10 years ago

By adding to Luminus, do you mean the project template? I can understand your worry to include it in lib-noir, but excluding everyone who doesn't use Luminus doesn't sound that useful either. How about a dedicated project like noir-stacktraces?

yogthos commented 10 years ago

So, aside from CSS styling how would this be different from the Ring stacktrace exception wrapper?

ccfontes commented 10 years ago

That's totally cool! I didn't know about wrap-stacktrace-web. Anyway, it seems there is more than a styling diference. The criterion for highlighting with the Noir style is: "does this namespace belong to this project?", whereas the ring one means something I cannot grasp yet. An excerpt of the same stack trace with the two different styles follows: screen shot 2014-06-16 at 10 44 33 screen shot 2014-06-16 at 10 45 24

The screenshot with the Noir style was taken from my own in-house adaptation, though. Example: I couldn't make it know the current namespace dynamically, so I had to do it statically, But I think the criterion is still the same. It should be confirmed if the original criterion is really the same.

IMO, it's useful to have the project forms highlighted, but others may find other information more useful.

yogthos commented 10 years ago

Noir kept track of project namespaces explicitly, but this wouldn't be simple to port to a standalone library. I agree that there would be value to that, but it's a bit of a question as to how to accomplish this in automated fashion.

ccfontes commented 10 years ago

I'm going to try it.

yogthos commented 10 years ago

@ccfontes you could do something like the following to get a list of all the namespaces that belong to the project:

(ns classpath
  (:require [clojure.string :as str]))

(defn project-path []
  (-> (System/getProperties)
    (.get "clojure.compile.path")
    (.split "/target")
    first))

(defn get-ns-name [file]
  (with-open [rdr (java.io.PushbackReader. (clojure.java.io/reader file))]
    (binding [*read-eval* false]
      (second (read rdr)))))

(defn list-namespaces []
  (->> (project-path)
       clojure.java.io/file
       file-seq
       (filter #(.endsWith (.getName %) ".clj"))
       (map get-ns-name)))

The above should extract all the names for the local namespaces in the project.

yogthos commented 10 years ago

@ccfontes so looks like I've got this working here

ccfontes commented 10 years ago

Nice! I was going to start working on that just now haha. Sorry for all the trouble.

yogthos commented 10 years ago

No problem, let me know if it's working as expected and feel free to send a pr if you'd like to change anything.

ccfontes commented 10 years ago

Awesome! It works :D I'm closing this.