Conversation
|
Thanks for the PR! It looks like this shouldn't affect performance in the 'off' case, which would have been my main concern. I'm down with the basic idea and the fn interface, but not really stoked about the 'boolean or fn' thing. What do you think about leaving the boolean as-is, and just pulling the current validation logic (with the signature you suggest) out of the macro as a defn |
|
the |
|
Great, thanks! |
|
Where should the |
|
I was going to try putting it in I'll move forward with it in |
|
Where should this be documented? Just on the |
|
Also this change causes a couple tests to fail because they expect an inlined exception thrown, and we now have a new function at the top of the stack trace. Switching I can change the test to specifically look at the second stack trace element instead of the first... |
063f928 to
ed126a8
Compare
|
Pushed a new commit with the changes described |
|
Aww crap, now it all comes back to me. I think the 'top of stack trace' is actually really important, that's what the user will see as the problem and it's really unhelpful if it doesn't actually reference the function in question. (That's why I hadn't already pulled out something like My apologies for potentially leading you astray. Can you see a way to patch this up? E.g., manually filtering the stack before throwing. Or I guess the alternative is to go back to what you had before? As for placement, I don't think it can go into As for documentation, I think just on the var seems reasonable. I haven't heard this request before, and I think it would probably be more of a distraction than a help to mention it in e.g., the readme. Thanks and sorry again for the brain fart. |
|
Is there a context where the user only sees the topmost stack frame? Otherwise I don't think this would be any worse than what users currently put up with when throwers use I don't think my original implementation would be any better, since the user still has to provide a function that would end up at the top of the stack trace. I'm not familiar with the implications of trying to edit jvm stack traces, but I can look into it. |
|
Yes, for example in my cider REPL only the top frame is printed (and the trace pops up in another tab). Here's a transcript showing what I see and a potential workaround (in the JVM at least). user> (defn foo [] (throw (RuntimeException. "hi")))
#'user/foo
user> (defn bar [] (foo))
#'user/bar
user> (bar)
RuntimeException hi user/foo (form-init7240245945236560886.clj:1)
user> (defn bar [] (try (foo) (catch Exception e (.fillInStackTrace e) (throw e))))
#'user/bar
user> (bar)
RuntimeException hi user/bar (form-init7240245945236560886.clj:1)(FWIW, I think your initial implementation has the property that the stack trace remains the same if you don't provide a custom handler, which will be true a vast majority of the time I imagine. ) |
|
Yes it's true that the old impl doesn't change the stack by default. If that's good enough from your perspective I can just go back to that. Perhaps to avoid the |
|
Sounds good to me, thanks! On Fri, Jul 22, 2016 at 10:28 PM, Gary Fredericks notifications@github.com
|
This allows users to redefine the function to get custom validation behavior (e.g., log warnings, probabilistic checks, etc.).
ed126a8 to
78cf0d2
Compare
|
Okay, I've pushed those changes (with Note that I haven't run the clojurescript tests, as I didn't have a js runtime handy. |
|
Looks good, thanks! Apologies again for the back and forth. |
|
Just released 1.1.3 with this change. |
|
Looks great, thanks! |
this is a proof-of-concept for being able to customize the fn-validation logic (by setting
use-fn-validationto a function), which lets you implement things like:I'd be happy to tweak, add tests, etc. if this is a desired feature.
The main use case for this for me is when retrofitting schemas on a legacy project, it's nice to be able to deploy the schemas to production to get feedback about their correctness without causing exceptions to be thrown.