feat: snafu error with better stack trace#717
Draft
VendettaReborn wants to merge 1 commit intoWatfaq:masterfrom
Draft
feat: snafu error with better stack trace#717VendettaReborn wants to merge 1 commit intoWatfaq:masterfrom
VendettaReborn wants to merge 1 commit intoWatfaq:masterfrom
Conversation
Contributor
Author
|
bad(for developers) error msgs: |
Contributor
Author
Contributor
Author
|
in this error, we can do similar things thanks to |
Contributor
There was a problem hiding this comment.
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
clash_lib/src/error/dns.rs:9
- The variant name 'InvaldDomain' appears misspelled. Consider renaming it to 'InvalidDomain' for clarity.
InvaldDomain {
clash_lib/src/app/dns/resolver/enhanced.rs:600
- This call to self.exchange(message).await is recursively invoking the same function, which may result in infinite recursion. Consider calling 'exchange_no_cache' or the intended non-recursive method instead.
let rv = self.exchange(message).await?;
| source: crate::error::DnsError, | ||
| }, | ||
| #[snafu(display("empty dns"))] | ||
| DsnEmpty { |
There was a problem hiding this comment.
The variant name 'DsnEmpty' seems to be a typo. Consider renaming it to 'DnsEmpty' to match the intended meaning.
Suggested change
| DsnEmpty { | |
| DnsEmpty { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
anyhowin 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_debugmacro, which will take thelocationfield as the file location in backtrace, and will takeerrorfield 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
Locationis 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