Comments (5)
Another possible idea that I'm less sure about is OkPretty
as a replacement for calling ok()
printing the diagnostic when it fails.
pub trait OkPretty {
type Output;
fn ok_pretty(self) -> Option<Self::Output>;
}
impl<T, E> OkPretty for Result<T, E>
where
E: Diagnostic + Sync + Send + 'static
{
type Output = T;
fn ok_pretty(self) -> Option<Self::Output> {
match self {
Ok(output) => Some(output),
Err(diagnostic) => {
println!("{:?}", Report::new(diagnostic));
None
},
}
}
}
If I could pick one, it'd definitely be UnwrapPretty
but I think both would be nice.
from miette.
I kinda like this idea, but I'm also debating whether it's good to include in miette.
Philosophically speaking, I think it's important to avoid unwraps as much as possible, and miette is designed with the intention of making it easier to avoid them.
But I can see how sometimes you just want to unwrap, such as tests! and how UnwrapPretty
might be useful there.
That said: tests are not typically a place where I think fancy-looking diagnostics are really necessary. Fancy diagnostics are more intended for end-users of a tool.
I also definitely wouldn't want OkPretty
because we should absolutely not be logging arbitrarily like that. I think doing that is a very application-specific decision to make, not something to encourage.
from miette.
Fair, OkPretty
is pretty out there.
As someone writing a compiler right now, being able to unwrap in my tests and actually see where the error happened is incredibly helpful.
from miette.
Yes, but the cost of just adding this as your own utility, since you find it useful to you, is very very low. It might be best to keep it that way.
from miette.
Fair I did in fact implement this for my project.
I just meant that there are real use cases for this. Whether there are enough to justify inclusion 🤷♀️
https://github.com/esoterra/claw-lang/blob/main/crates/common/src/diagnostic.rs
from miette.
Related Issues (20)
- Unclear which part of long lines is being pointed to HOT 1
- Change `link` label to something else HOT 1
- New Crates.io Release? HOT 3
- Potentially broken word wrapping on `main` HOT 3
- Update owo-colors to v4? HOT 5
- Can't get `syntect-highlighter` to work HOT 3
- Remove severity from diagnostic output HOT 1
- Compile to wasm32-unknown-unknown / Compile without `terminal_size` HOT 4
- Errors with zero-length span and no context lines are mostly pointless HOT 1
- 要是错误提示能使用中文输出就好了! HOT 5
- Failing tests with `--all-features` HOT 1
- Feature request: output an error as `json::Value` or `serde_json::Value` directly HOT 2
- Feature request: Span line limit for diagnostics HOT 3
- Help: Sub Errors HOT 3
- Is there a reason that `Report` doesn't implement `Error` and `Diagnostic`? HOT 2
- Converting a `Report` to a `Box<dyn Diagnostic>` wipes all `Diagnostic` information HOT 1
- Improve compilation speed by reducing expanded llvm lines HOT 4
- Add `#[cold]` to some of the constructor functions HOT 3
- `#[label]` derive doesn't seem to work with `Option<T>` where `T` implements `Into<SourceSpan>` but not `Copy`
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.