Comments (4)
actuallly I don't think we need this, if we have #[error(transparent)]
already...
from miette.
@zkat This is still necessary. Just placing #[error(transparent)]
on a single item enum variant doesn't do anything WRT the Diagnostic implementation. It needs to generate code that implements Diagnostic through the inner type, the way thiserror's does for the Display
and Error::backtrace
etc implementations.
Thiserror does give you the From implementation via Variant(#[from] Inner)
for free.
The use case for miette is pretty obvious, same as thiserror's, but for some context, I'm doing this:
#[derive(Debug, Error, Diagnostic)]
enum Diag {
#[error(transparent)] #[diagnostic(transparent)] Error(#[from] Error),
// The rest of the variants go here, all warnings/advice, no errors
}
// this would be weird -- you could fail your whole thing because of a warning
fn bad_function(...) -> Result<i32, Diag> {}
// this way your Err case is never a warning, so you are never in the situation where
// there is only a warning but you don't have an Ok value to continue with
fn better_function(...) -> Result<i32, Error> {}
from miette.
There is another way, which is to box all of your diagnostics and let the dynamism do the work. But sometimes you don't want to erase all the types, if you're like me (the guy from twitter who wanted to collect all the diagnostics into a Vec and expose them to library users) then maybe you just want the one type. The code
goes a long way but I'm not sure.
You might also want to delegate only some of the Diagnostic implementation. I'm thinking about having a lot of different variants where practically every single one has a source, a snippet and an optional hint. Being able to forward the snippet implementation to a single struct Snip
but provide a new code
etc would be very useful.
from miette.
I'm having a crack at a PR for this
from miette.
Related Issues (20)
- License malformed
- Switching out `atty`? HOT 4
- Panic when printing a report containing source code with debug HOT 1
- `SourceSpan` from `LineColumn`? HOT 1
- Related reports render with the severity of the parent report.
- Allow the inner source type of a `NamedSource` to be borrowed directly HOT 1
- More controlability for the `label` HOT 5
- `Severity` should implement `Ord`
- Allow spans in `help` to provide structured suggestions HOT 3
- Backtrace and Spantrace support HOT 5
- Update miette-derive syn dependency to syn 2 HOT 2
- Still print the name of the SourceCode even if all the labels are invalid
- How to manually collect and print errors HOT 2
- Add source slices HOT 1
- Expose access to line and column info from SourceSpan HOT 3
- Add struct for dynamic creation of diagnostics HOT 2
- Use serde HOT 4
- Constify `SourceOffset` and `SourceSpan` HOT 1
- Add `FixIt` support
- Fix overlapping labels 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 miette.