mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 11:15:54 +03:00
[GH-ISSUE #326] Migrate all from error-chain to failure #151
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bluejekyll on GitHub (Jan 6, 2018).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/326
https://github.com/withoutboats/failure
https://docs.rs/failure/0.1.1/failure/
@silwol commented on GitHub (May 16, 2018):
I'm investigating a possible transformation to failure.
Using the structure as described in https://boats.gitlab.io/failure/error-errorkind.html seems to allow rather straight-forward translation.
Right now, the error_chain! macro uses names for the parameters, looking like this:
This would translate to either of these:
Variant 1:
Variant 2:
In variant 1, the ErrorKind definition is much more readable, describing the parameters by name, so I would prefer that. This causes changes all over the rest of the source code wherever errors get constructed, which would not be necessary for variant 2:
must be changed to:
or in the optimal case that the variable already has the right name:
Is there any significant reason to prefer one variant over the other in your opinion?
@bluejekyll commented on GitHub (May 16, 2018):
Thank you for looking into this change and for taking the time to put together a proposal. This is a great description of the different options.
Between the Variant 1 and 2, I also like the expressiveness of Variant 1, though 2 is a little more ergonomic. The nice thing about 1 is the expressiveness and clarity about what the associated field actually represents. So if you want to go in that direction, that would be great. Though, it's something that I don't think is a a huge issue. If using Variant 1 makes converting to Failure a larger and more painful task, then I would suggest using 2 for now to reduce the effort.
I think there is a different question here that is implied with the name
ProtoErrorKindand that's: do we need a wrapper typeProtoError(ProtoErrorKind). As an example, I wanted to use this pattern in a different project: https://github.com/bluejekyll/foundationdb-rs/blob/master/foundationdb/src/error.rs#L30-L58. The reason for that was because of shared information (thatshould_retryfield) which needed to be tracked across all kinds of errors. I don't think we have that issue here and can probably get away with a singleProtoErrorenum as the error type. This should be true for the general case of all the crates.I'm not sure if you're planning to do the work for all the projects (client, server, proto, resolver). The client errors are a bit of a mess. They are holdovers from the very beginnings of the project. I think the right thing would be to consolidate those errors into a single
ClientErrortype, and drop all the differences, but I'm open to other suggestions there.@silwol commented on GitHub (May 16, 2018):
I just made a short test without a ProtoErrorKind, just making ProtoError an enum, as described in https://boats.gitlab.io/failure/custom-fail.html because the idea is tempting.
However, the referenced cause error type
FromUtf8Errorprevents me from implementingCloneforProtoErrorbecause the upstream error type does not permit copying or cloning.Cloneis required by theFromProtoErrortrait.Correct me if I'm wrong, but from my perspective it seems that a separation into an
Errorand anErrorKindwill be necessary, at least forProtoError. I haven't looked into the other projects yet.I managed to transform the
protoproject to a split-upError+ErrorKindvariant. This caused API changes which require modifications in the other projects, so the migration will surely break the exposed API surface.For the embedded variables, I will use the mode proposed in variant 2, except for enum values containing multiple variables (e.g.
IncorrectRDataLengthRead{read: usize, len: usize}which would be confusing without names).I intend investigate migration of the other projects as well, because I think it's good to switch everything to the failure crate at once.
@bluejekyll commented on GitHub (May 16, 2018):
FromUtf8Erroris Send/Sync, so maybe just wrap it in anArc? I think that should work. I remember needing Clone for some reason or other, but that may have been to work around the fact that the library wasn't properly enforcing Send before. So that may not be an issue now. So maybe we can drop the Clone requirement?I haven't looked at these error types in a while, so I'll go with your opinion on it since you're looking at it now.
Wonderful
I agree, and thank you!