Comments (6)
One question I thought of when looking at that section, is "can we apply this multiple times to a given entry".
i.e.
#[derive(Debug, Snafu)]
enum Error {
SourceNeedsToBeConverted {
#[snafu(
source(from(another::ErrorIO, from_io_error)),
source(from(another::ErrorInitialization, from_init_error))
)]
source: Box<another::ErrorBase>,
},
}
I suspect the answer is currently "no".
But, I suspect but such a method might help me reduce the number of error types I end up with in my applications.
from snafu.
can we apply this multiple times to a given entry
This was an idea that I had in mind when implementing it. You are right that it's not currently supported. It's not a trivial amount of work, but it isn't impossible either.
from snafu.
I think it'd be worth having a separate issue for supporting multiple source(from)
attributes. To rephrase, the goal would be to allow multiple source error types to use the same context selector, right?
#[derive(Debug, Snafu)]
enum Error {
IoOrFmtError {
#[snafu(source(from(std::fmt::Error, from_fmt_error)))]
#[snafu(source(from(std::io::Error, from_io_error)))]
source: Box<ErrorBase>,
},
}
fn_that_generates_io_error().context(IoOrFmtError)?;
fn_that_generates_fmt_error().context(IoOrFmtError)?;
And to clarify the goal of this issue, I think we want example(s) of what source(from)
can be used for, and in particular how it impacts the context()
call, if at all?
I've used it for handling recursive errors, which I think might be a common case, so maybe that's something I could write.
from snafu.
supporting multiple
source(from)
attributes
(This strikes me as somewhat similar to the request in #123 for "N->1" error mappings, except using multiple concrete types instead of a trait bound. I wonder if those ideas could be unified?)
from snafu.
I think it'd be worth having a separate issue for supporting multiple
source(from)
attributes.
Agreed. I mostly didn't do it originally to avoid YAGNI; was hoping that if someone needed it they would create an issue for it.
And to clarify the goal of this issue, I think we want example(s) of what
source(from)
can be used for, and in particular how it impacts thecontext()
call, if at all?
That's a specific example, yes. This issue was also broadly about how most of the attributes on that page show the #[snafu(...)]
part, but not what happens "at the other end". The Display
implementation was more recently touched and does at least attempt to show that.
One thing that I worry about with the user's guide is getting just the right amount of duplication. Too DRY and the documentation becomes a maze of links where you have to read everything to understand anything. Too WET and we run a higher chance of having out-of-date, misleading, or just plain incorrect information, lowering the confidence in the guide.
Concretely, I think that showing "what it can be used for" might be a better as a part of #104.
from snafu.
using multiple concrete types instead of a trait bound. I wonder if those ideas could be unified?
Some unification would be cool, but I haven't seen how yet.
from snafu.
Related Issues (20)
- alternate `Display` to include the source chain HOT 4
- Best way to consolidate error types HOT 9
- Investigate switching `IntoError` from an associated type to generics HOT 2
- Investigate adding `ResultExt::boxed` and `::boxed_local`
- Is it possible to automatically include fields in error's display? HOT 2
- Consider adding #[snafu(transparent)] HOT 6
- Support Serde for the built-in types HOT 6
- multiple error types (struct and enum) and generic `IntoError` HOT 2
- Simple context usage, mysterious compile error HOT 2
- Use the same deprecation macros on the no_std Error as the official Error HOT 3
- Add an ensure macro that works with pattern matching HOT 2
- Restore support for yeeting context selectors HOT 1
- Print multi-line errors on their own lines in `Report` HOT 2
- Const generics seem to be giving the derive macro trouble HOT 2
- question: Best practice for automatic error conversion over two module levels?
- Cannot use a generic with a whatever variant
- Incorrect year in changelog
- No apparent way to have an error enum variant documentation generated from a display string HOT 5
- Why isn't Whatever Send + Sync by default? HOT 5
- `Report` print doesn't prefix with "Error: " HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snafu.