-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improving error messaging #25
Comments
Hi, I've read that this is |
Hi @AniketARS, Thanks for the interest in working on this. Is this part of Outreachy? Before assigning issues it would be good to have the project set up (opam installed and the project building and being tested with |
Yes, I'm in contribution period of |
Welcome @AniketARS and nice that you want to contribute!
Have you already had a look at the tutorials on the ocaml.org site? I personally also like the online book Real World OCaml a lot, particular the first chapter Language Concepts gives a good overview over the commonly used aspects of the language, but it might be a bit long to just get started. There is also a fun-mooc course on Functional Programming in OCaml. By the way, what's your background? Do you already have some experience with functional programming? |
I will consider myself as a beginner in this context because I have basic experience with functional programming but with |
All ok @AniketARS, is there anything I can help with if you are still working on this issue ? |
Yes i found the line responsible for this issue: let mk_pat_match ~loc cases =
let cases = cases @ [ ([%pat? _], [%expr Error (`Msg "err")]) ] in
Exp.function_ (List.map (fun (pat, exp) -> Exp.case pat exp) cases) But what i want is to pass mk_pat_match ~loc
[ ([%pat? `Float [%p argument]], [%expr Ok [%e expr_arg]]) ] So that i can produce error stating Type-Mismatch: Given |
Sounds plausible to me. The |
Hello @patricoferris and @pitag-ha , Am an outreachy applicant. |
Hi @DeborahLanyero, nice that you're interested in contributing to OCaml. Welcome! We usually ask our applicants first to set up a working project environment and, once that's done, to sign up for an issue. Would that be ok for you? |
Yes am okay with it. Thank you. |
Hello @pitag-ha , I have completed setting up the environment. and am currently going through the resources availed to get familiar with the language. |
Nice @DeborahLanyero ! You can start working on the issue now. I'm Aya one of the co-mentors, definitely let us know of any questions 🙂 |
Hey @lekha06 ! It seems Deborah is looking into this issue already. Have you looked at the other issues listed on the contributions period info page? For example, this is one of the easy first issues from that list: NathanReb/ppx_yojson#27 You can start with that one instead. |
Hey @DeborahLanyero are you still working on this issue? What do you have so far? patricoferris added some info on how to run the tests on this page, which might be helpful to you. Also, you might want to check out the explanations here on how the The next step is probably to have the error message say what is the expected type only, like: "Error: expected type." Do you already have some ideas on how to make that change? Let us know what you are trying and if there is something we can help you with! |
Hello @ayc9 , yes am still working on this issue. I don't know how to add the message also I have been reading about exception handling using the materials provided. |
Basing on that example, did you mean that i can just change the message from "err" to something like "Error: expected type "string" "? For the different cases int, float , string, boolean? |
Hey @ayc9 ,@pitag-ha If so, that I can change the message from "err" to a more desirable one like "Error: expected a string" My question is should I remove the expression(expr_arg) and change the cases to: |
Hi @DeborahLanyero -- On line 162,
Do these options make sense? Let us know which one you try and how it works out! |
Yes please, it does make sense , let me try it out and give feedback accordingly |
hi @DeborahLanyero are you still working on this issue? If not, I'd like to look into it... |
I think it's okay for you to work on this @prosper74 if you still want to ^^ |
Fixed in #32 |
Feature Request
Error handling in the deriver is not great which was helpfully discovered this thanks to @guptadiksha307.
The biggest improvement would be to provide better error messages when the wrong type of Yaml value is uncovered. For example this code could be a lot better and at least described what it was expecting to find https://github.com/patricoferris/ppx_deriving_yaml/blob/main/lib/value.ml#L162 !
An example
Consider the following little program:
In the data (the
yml
string) you can the population of Belfast is given as a number634594
rather than a string"634594"
. The type ofpopulation
inplace
is astring
however so the generatedof_yaml
function will fail because it will try to read astring
and instead find a number!We might expect the error message to tell us something informative like
Was expecting a string but got a <x>
, but instead we get the following useful error message!If it is useful the code above was compiled with:
The text was updated successfully, but these errors were encountered: