Skip to content

Parameterize the println that informs of the fallback cases #10

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vemv
Copy link

@vemv vemv commented Aug 3, 2018

Hi there!

I was finding the (println "[PINPOINTER] Failed to analyze the spec errors, and will fall back to s/explain-printer\n") somewhat noisy and with limited usefulness.

This PR leaves up to the user whether to run it (by passing an empty fn), or to actually log the incidence in detail: it can be very handy to access the underlying exception, that way one can try to fix it.

You can try out these changes by raising an error (e.g. https://github.com/athos/Pinpointer/issues/2) with the option being passed.

Cheers - Victor

@vemv vemv force-pushed the parameterize-fallback-reporting-fn branch from 4912e74 to 9df8549 Compare August 3, 2018 06:58
@athos
Copy link
Owner

athos commented Aug 7, 2018

Hi, @vemv! Thank you for the feedback 😄 And I’m sorry for my slow response.

I agree that that warning message can be somewhat noisy, so improvements around it are very welcomed.
OTOH I’m also considering some other possible options than this PR proposes since I’m not sure if it is that likely that users want to customize “how the warning message is printed” or “what is printed as the warning message”.

I feel more like users would just want to disable showing that message, eg.:

(p/pinpoint spec input {:fallback-on-error :disable-warning-message})

Or, to give users more liberty of controlling the behaviors on error, the following might seem more intuitive:

(p/pinpoint spec input {:on-error (fn [ed err] (println “Something bad happened!”) (s/explain-printer ed))})

What do you think of these? Do you have any concrete use case of this change in mind?

@vemv
Copy link
Author

vemv commented Aug 8, 2018

Hey there @athos ! Thanks for the reply.

(p/pinpoint spec input {:fallback-on-error :disable-warning-message})

An option which can have nil, true, false or :disable-warning-message values seems overloaded to me. Even more if we introduced e.g. :print-exceptions in a future (for making the default logger print the exceptions).

(p/pinpoint spec input {:on-error (fn [ed err] (println “Something bad happened!”) (s/explain-printer ed))})

I like this option better. But, one has to remember to call s/explain-printer, which is an implementation detail of both clojure.spec and pinpointer.

It's a cost I personally could assume though, no biggie.

Do you have any concrete use case of this change in mind?

Primarily, being able to debug things (since no exceptions are logged). Also, the warning message is not tremendously useful to me, as I can guess when is Pinpointer being used and when not.

Also, the message happens to break some unit tests we have.

Cheers - Victor

@vemv
Copy link
Author

vemv commented Aug 28, 2018

Hey there,

kindly let me now what you think when you have a chance.

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants