feat: snafu error with better stack trace #717
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤔 This is a ...
🔗 Related issue link
#405
💡 Background and solution
background
greptimedb has done a great job in engineerizing error handling in rust. currently, we are in great debt of error-handlings, it's inconvenient for debugging(i had a deep feeling about that when implementing zero-copy).
so i tried a POC project in https://github.com/VendettaReborn/better-error-experiment, and it worked as expected, with NOT TOO MUCH overhead added.
And i just tried it our project, removing
anyhow
in both ClashDnsResolver and Hysteria protocol implementation, i think it may serve as a draft and better POC now.solution
implement(copied from greptimedb)
stack_trace_debug
macro, which will take thelocation
field as the file location in backtrace, and will takeerror
field as the external error field. it's important that the two field name, 'location' and 'error' is hardcoded, but that's enough for now.as you can see, with the propagate of Snafu Error, the
Location
is accumulated as a list, which will serve as the virtual error stack at the end.overhead: after defining all error kinds properly, the only overhead is adding
.context(xxxSnafu)
before using?
orxxxSnafu.fail()
for rust-style error propagate.TODOs
crates/...
☑️ Self-Check before Merge