-
Notifications
You must be signed in to change notification settings - Fork 27
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
Enforce callers pass a path for debugging purposes, and update ppx to… #55
Conversation
… generate better location info for decode failures.
…differen key than 'path' for the location information.
So I finished this version but I'd really like some input or help making this interface less invasive to calling code... It really stinks to 1 have a major version bump in the API and 2 to force callers to have to pass Generally I'd prefer if we could do more PPX magic and somehow generate the Location info wherever something like Also, the formatter I have from bs-platform doesn't play nice with this so I tried generally not to touch any formatting stuff but if there's a tool I can run on the project to get this PR up to speed with a particular formatting ruleset I'd be happy to run that. |
@ryb73 you have any thoughts on this? |
Can you share an example before/after error message? Would be interested to see how this looks for folks using decco. |
@rickyvetter Of course! |
Oh wow. I'm oblivious. Looks cool! |
I'm not a fan of the breaking API change that'll force users writing "custom decoders" with the Codecs to pass an argument, it's better in that it'll force callers into a debuggable pattern but I wish I could code gen location info for failures directly to call sites of stuff... |
Thanks for the contribution @erlandsona. I'm afraid I'm not really understanding the use case behind this. It's a pretty standard thing for functions that can fail to return |
Two things...
My power just went out so I'm typing this up on my phone otherwise I'd have more complete examples to share here. But I'm hoping I'm making enough sense otherwise. |
Sorry about the power, hope you got it fixed!
Is it not sufficient to get the location information at the call site when it fails? let a = [||];
switch (Js.Array.pop(a)) {
| Some(v) => Js.log2("got value", v);
| None => Js.log2("failure at", Pervasives.__LOC__);
}
// same concept applied to decco
switch (mytype_decode(json)) {
| Ok(v) => Js.log2("got value", v);
| Error(_) => Js.log2("failure at", Pervasives.__LOC__);
// or: // | Error(_) => Js.Exn.raiseError("failure")
} |
Alrighty I'm back at my machine... Powers on and all is right with the world 😆
It is sufficient to configure the location information at the call site when it fails but I don't believe that a special "Debugging" (compiler hook?) should be something the callers have to be aware of to benefit from.
Aside from my answer to the first point here's some code... CodingQuery.re
Basically this is how we do Safe-ish HTTP stuff safely hookin' into our Reductive / Bs-rx infra... Notice each As it stands currently if either of these decoders fail say because the Preferably and what this PR add's to the project is that it forces callers of the Without these changes the callers would have to do something like It also doesn't fix the location info for the messages pointing to failures for decco generated decoders like the These changes result in an error with some location info baked in EG: Which! Is why I'd generally prefer to bake it into the lib in a more transparent way but that's where I'd need your help @ryb73. Otherwise, I think these changes build in enough value as they are to solve for at least my teams use case and I hope they can be helpful to others using this as well. |
Any thoughts on this @ryb73 ? |
This PR seems that it fixes #63 and it's really an improvement over the error messages that decco provides now. Can we do something to resolve this? I understand the differences in opinions, but I tend do agree that having the location as a default for the lib would be very beneficial. |
This isn't something I'd want on by default. I use the decco errors to generate validation errors in my library API, and I wouldn't want my source file names leaking into those. I can see it being useful in a standalone app scenario, but it's definitely not in a library scenario. |
I agree with @TheSpyder, this doesn't belong in a library. Moreover, unless I'm misunderstanding the changes in this PR, it's unrelated to issue #63. I'd be happy to accept a PR that does fix #63. |
… generate better location info for decode failures.
So this is just a first pass at upgrading decco for better location information on decode errors. I haven't update the tests yet because I'm not sure how to fix this issue where it seems like the
Pervasives.__LOC__
calls are being evaluated when the ppx is run rather than printing that expression for bucklescript to compile.If I someone can help me figure that part out then I can fix the tests and we all can go from this
{path: "[0].id", message: "Not a int", value: nil}
to something more along the lines of this...
{path: "[0].id File "MyCustomRecord.re", line 8, characters 7-60", message: "Not an int", value: nil}
This will also close #54