Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap-stacktrace is awkward to call conditionally #9

Closed
technomancy opened this issue Aug 2, 2012 · 5 comments
Closed

wrap-stacktrace is awkward to call conditionally #9

technomancy opened this issue Aug 2, 2012 · 5 comments

Comments

@technomancy
Copy link

Typically you only want wrap-stacktrace to take effect in a development setting. Doing this with environ looks something like this:

(jetty/run-jetty (-> #'app
                     ((if (env/env :dev)
                        trace/wrap-stacktrace
                        identity))
                     [...])
                 {:port port :join? false})

If wrap-stacktrace took a second argument to turn it into a no-op, it would be easier to use in the context of ->.

(jetty/run-jetty (-> #'app
                     (trace/wrap-stacktrace (env/env :production))
                     [...])
                 {:port port :join? false})

What do you think?

@seancorfield
Copy link

To me that reads as if wrap-stacktrace should apply only in a production setting. Wouldn't the more natural usage be:

(trace/wrap-stacktrace (env/env :dev))

or at least:

(trace/wrap-stacktrace (not (env/env :production)))

@technomancy
Copy link
Author

Good call; the option should probably be stated in the positive rather than the negative.

@weavejester
Copy link
Member

Sorry for taking a while to notice this. I'm not getting notifications for the ring-clojure organization anymore.

@weavejester
Copy link
Member

I think that this might not be the best idea...

The wrap-stacktrace middleware isn't the only middleware a developer might want to use only in development, and the idea of encasing an if-statement in every middleware function that might not be used in a production environment strikes me as redundant.

Instead, perhaps just factoring development middleware into a separate function could be a solution:

(defn wrap-dev-middleware [handler]
  (if (= (env :ring-env) "production")
    handler
    (-> handler
        wrap-stacktrace
        wrap-reload
        wrap-whatever-else)))

@technomancy
Copy link
Author

Yeah, on further consideration this is probably too specific and not the right place for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants