-
Notifications
You must be signed in to change notification settings - Fork 68
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
Error collector #164
Error collector #164
Conversation
I experimented with this in
|
I think having a let mut errors = darling::Error::collector();
for attr in input.drain(..) {
let unnest = outputs
.iter_mut()
.find(|(ptattr, _)| attr.path.is_ident(ptattr));
if let Some((_, unnest)) = unnest {
match unnest_from_one_attribute(attr) {
Ok(attr) => unnest.push(attr),
Err(e) => errors.push(e)
}
} else {
for (_, output) in outputs.iter_mut() {
output.push(attr.clone());
}
}
}
errors.checkpoint() Key differences:
My main concern with this is the lack of prior art; I haven't had time to look for other examples of crates that accumulate/collect errors to see how they do it. I wonder if this is a |
Makes sense to me. It should probably still
I think whether using
That could be useful.
I did look for some prior art. I'm sure I've seen something like this somewhere but wasn't able to find it. I don't think there's any in std.
I find |
I did another search for prior art and found these:
I am definitely unsure about the right names for Other name/bikeshed suggestions:
I quite like if let Some((_, destination)) = unnest {
if let Some(unnested) = errors.handle(unnest_from_one_attribute(attr)) {
destination.push(unnested);
} Of course |
Hmm, |
Does it make sense for |
Interesting idea. I think I like it. But it ought to happen on any plain drop, so that ytou can't ship code that triggers it by mistake, even if you only test the success case. This is slightly fiddly inside I'll revise this MR tomorrow. |
That's true, though |
Suggested in passing in discussions in the MR.
With the drop bomb, |
* Rename finish(T) to finish_with(T) * Add finish() with no args * Tweak must_use messages * Add unit test for dropping while holding errors
We're getting very close here. I think we can do better than Part of my gripe with those two names is that we encourage this to be called |
That wasn't stable in Rust 1.31
To my mind I see your problem with How about renaming errors.handle_from(||{
let validated = thing.validate()?;
outputs.push(validated);
Ok(())
});
|
I'm officially in love with the use of You're right about I think I prefer Is it bad that I actually quite like |
"Deal with" is fine in British English too. It is very slightly less formal, I think. My only concern with it is whether non-native speakers of English would find it confusing (especially because of the way Rust uses I looked at Wiktionary's entries for deal with and handle. "Deal with" is less ambiguous if you know what it means at all (since it can't mean "get a handle"), but as I say I wonder if it's too confusing if you don't. I did a search of some random local rustdocs here "handle" as in "deal with" is used a fair bit in web frameworks as a thing you do to requests or, indeed, errors. Of the things listed in Wiktionary's synonyms sections for these words (I tried an online thesaurus but it was no use) I think "manage" is a possibility. Also maybe "consider" |
So, having slept on it I think best would be |
I'm supportive of |
Co-authored-by: Ted Driggs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great; really appreciate all the work you've put into it, and think this is a great addition to darling
.
A final note on this that makes me happy: To merge two accumulators is as easy as |
Thanks for your kind words :-). You're very welcome. |
I noticed the poor ergonomics of
Error::multiple
. I see there's an issue for this already, #115.Here is my idea of what a nice API woudl be like. It handles not only the awkward
if errors.is_empty()
at the end, but also collection of errors as we go. This is IMO a better alternative to #155.