-
Notifications
You must be signed in to change notification settings - Fork 24
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
Adding examples to error messages #58
Comments
@jefffriesen It's a good idea! I do think examples would be really useful in this context, especially for beginners who may have less familiarity with the spec syntax. This isn't well documented in Expound currently (hmm, maybe I need to use Dynadoc to document the API 😄 ), but it's possible to modify the default Expound printer, so any user could add extra info like the defexample to the output. Unfortunately, right now the information that spec returns does not include the symbol of the function that was called, so there is no way to look up the example (which requires knowing the namespace and function name). The issue tracking this is https://dev.clojure.org/jira/browse/CLJ-2166 (please log in and vote for it! 😄 ) Once that fix makes it into Clojure spec, I will write up some example code of how to include examples defined via |
Sounds like a great plan. |
FYI https://dev.clojure.org/jira/browse/CLJ-2166 has been resolved on 2018-06-26 and is available in clojure.spec release 0.2.168 |
Thanks again for the idea! Since I haven't seen a wide adoption of examples, I'm going to close this for now. If examples turn up in say, cljdoc and more people use them, I'd reconsider, but for now, I'm not inclined to add an additional dependency on expound. |
@bhb
The other day we talked about your ideas to add "did you mean..." examples to an error message by filling in the missing arguments based on the spec. I still think that's a great idea. Here is another cool approach that @oakes laid out in a gist: https://gist.github.com/oakes/8db57ac808bf6ec144d627fd83a89da3
It uses
defexample
s to show show an example of how a function can be used. (I appreciate his comment about how examples are especially helpful for non-English speakers).Maybe if a
defexample
is defined for a function, you could show that after anexpound
ed error message.Better yet - show everything:
expound
error messagedefexample
if it's available. This could also be collapsed by default in an IDEIf the
expound
error message wasn't enough for me to figure out my problem, I would love to have multiple examples right there, in context, for me to figure it out. It would be nice to not be overwhelmed with information so it would be nice to optionally expand them with keybindings (or clicking in an IDE UI).You could build this support directly into expound. Another direction could be that
expound
turns into a type of platform, where a user could install plugins such asdefexemple
or other things into it.What do you think?
This ticket may be too broad - feel free to close it in favor of more specific tickets.
The text was updated successfully, but these errors were encountered: