miette/
lib.rs

1//! You run miette? You run her code like the software? Oh. Oh! Error code for
2//! coder! Error code for One Thousand Lines!
3//!
4//! ## About
5//!
6//! `miette` is a diagnostic library for Rust. It includes a series of
7//! traits/protocols that allow you to hook into its error reporting facilities,
8//! and even write your own error reports! It lets you define error types that
9//! can print out like this (or in any format you like!):
10//!
11//! <img src="https://raw.githubusercontent.com/zkat/miette/main/images/serde_json.png" alt="Hi! miette also includes a screen-reader-oriented diagnostic printer that's enabled in various situations, such as when you use NO_COLOR or CLICOLOR settings, or on CI. This behavior is also fully configurable and customizable. For example, this is what this particular diagnostic will look like when the narrated printer is enabled:
12//! \
13//! Error: Received some bad JSON from the source. Unable to parse.
14//!     Caused by: missing field `foo` at line 1 column 1700
15//! \
16//! Begin snippet for https://api.nuget.org/v3/registration5-gz-semver2/json.net/index.json starting
17//! at line 1, column 1659
18//! \
19//! snippet line 1: gs&quot;:[&quot;json&quot;],&quot;title&quot;:&quot;&quot;,&quot;version&quot;:&quot;1.0.0&quot;},&quot;packageContent&quot;:&quot;https://api.nuget.o
20//!     highlight starting at line 1, column 1699: last parsing location
21//! \
22//! diagnostic help: This is a bug. It might be in ruget, or it might be in the
23//! source you're using, but it's definitely a bug and should be reported.
24//! diagnostic error code: ruget::api::bad_json
25//! " />
26//!
27//! > **NOTE: You must enable the `"fancy"` crate feature to get fancy report
28//! > output like in the screenshots above.** You should only do this in your
29//! > toplevel crate, as the fancy feature pulls in a number of dependencies that
30//! > libraries and such might not want.
31//!
32//! ## Table of Contents <!-- omit in toc -->
33//!
34//! - [About](#about)
35//! - [Features](#features)
36//! - [Installing](#installing)
37//! - [Example](#example)
38//! - [Using](#using)
39//!   - [... in libraries](#-in-libraries)
40//!   - [... in application code](#-in-application-code)
41//!   - [... in `main()`](#-in-main)
42//!   - [... diagnostic code URLs](#-diagnostic-code-urls)
43//!   - [... snippets](#-snippets)
44//!   - [... help text](#-help-text)
45//!   - [... severity level](#-severity-level)
46//!   - [... multiple related errors](#-multiple-related-errors)
47//!   - [... delayed source code](#-delayed-source-code)
48//!   - [... handler options](#-handler-options)
49//!   - [... dynamic diagnostics](#-dynamic-diagnostics)
50//!   - [... collection of labels](#-collection-of-labels)
51//! - [Acknowledgements](#acknowledgements)
52//! - [License](#license)
53//!
54//! ## Features
55//!
56//! - Generic [`Diagnostic`] protocol, compatible (and dependent on)
57//!   [`std::error::Error`].
58//! - Unique error codes on every [`Diagnostic`].
59//! - Custom links to get more details on error codes.
60//! - Super handy derive macro for defining diagnostic metadata.
61//! - Replacements for [`anyhow`](https://docs.rs/anyhow)/[`eyre`](https://docs.rs/eyre)
62//!   types [`Result`], [`Report`] and the [`miette!`] macro for the
63//!   `anyhow!`/`eyre!` macros.
64//! - Generic support for arbitrary [`SourceCode`]s for snippet data, with
65//!   default support for `String`s included.
66//!
67//! The `miette` crate also comes bundled with a default [`ReportHandler`] with
68//! the following features:
69//!
70//! - Fancy graphical [diagnostic output](#about), using ANSI/Unicode text
71//! - Screen reader/braille support, gated on [`NO_COLOR`](http://no-color.org/),
72//!   and other heuristics.
73//! - Fully customizable graphical theming (or overriding the printers
74//!   entirely).
75//! - Cause chain printing
76//! - Turns diagnostic codes into links in [supported terminals](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda).
77//!
78//! ## Installing
79//!
80//! ```sh
81//! $ cargo add miette
82//! ```
83//!
84//! If you want to use the fancy printer in all these screenshots:
85//!
86//! ```sh
87//! $ cargo add miette --features fancy
88//! ```
89//!
90//! ## Example
91//!
92//! ```rust
93//! /*
94//! You can derive a `Diagnostic` from any `std::error::Error` type.
95//!
96//! `thiserror` is a great way to define them, and plays nicely with `miette`!
97//! */
98//! use miette::{Diagnostic, SourceSpan};
99//! use thiserror::Error;
100//!
101//! #[derive(Error, Debug, Diagnostic)]
102//! #[error("oops!")]
103//! #[diagnostic(
104//!     code(oops::my::bad),
105//!     url(docsrs),
106//!     help("try doing it better next time?")
107//! )]
108//! struct MyBad {
109//!     // The Source that we're gonna be printing snippets out of.
110//!     // This can be a String if you don't have or care about file names.
111//!     #[source_code]
112//!     src: NamedSource<String>,
113//!     // Snippets and highlights can be included in the diagnostic!
114//!     #[label("This bit here")]
115//!     bad_bit: SourceSpan,
116//! }
117//!
118//! /*
119//! Now let's define a function!
120//!
121//! Use this `Result` type (or its expanded version) as the return type
122//! throughout your app (but NOT your libraries! Those should always return
123//! concrete types!).
124//! */
125//! use miette::{NamedSource, Result};
126//! fn this_fails() -> Result<()> {
127//!     // You can use plain strings as a `Source`, or anything that implements
128//!     // the one-method `Source` trait.
129//!     let src = "source\n  text\n    here".to_string();
130//!
131//!     Err(MyBad {
132//!         src: NamedSource::new("bad_file.rs", src),
133//!         bad_bit: (9, 4).into(),
134//!     })?;
135//!
136//!     Ok(())
137//! }
138//!
139//! /*
140//! Now to get everything printed nicely, just return a `Result<()>`
141//! and you're all set!
142//!
143//! Note: You can swap out the default reporter for a custom one using
144//! `miette::set_hook()`
145//! */
146//! fn pretend_this_is_main() -> Result<()> {
147//!     // kaboom~
148//!     this_fails()?;
149//!
150//!     Ok(())
151//! }
152//! ```
153//!
154//! And this is the output you'll get if you run this program:
155//!
156//! <img src="https://raw.githubusercontent.com/zkat/miette/main/images/single-line-example.png" alt="
157//! Narratable printout:
158//! \
159//! diagnostic error code: oops::my::bad (link)
160//! Error: oops!
161//! \
162//! Begin snippet for bad_file.rs starting
163//! at line 2, column 3
164//! \
165//! snippet line 1: source
166//! \
167//! snippet line 2:  text
168//!     highlight starting at line 1, column 3: This bit here
169//! \
170//! snippet line 3: here
171//! \
172//! diagnostic help: try doing it better next time?">
173//!
174//! ## Using
175//!
176//! ### ... in libraries
177//!
178//! `miette` is _fully compatible_ with library usage. Consumers who don't know
179//! about, or don't want, `miette` features can safely use its error types as
180//! regular [`std::error::Error`].
181//!
182//! We highly recommend using something like [`thiserror`](https://docs.rs/thiserror)
183//! to define unique error types and error wrappers for your library.
184//!
185//! While `miette` integrates smoothly with `thiserror`, it is _not required_.
186//! If you don't want to use the [`Diagnostic`] derive macro, you can implement
187//! the trait directly, just like with `std::error::Error`.
188//!
189//! ```rust
190//! // lib/error.rs
191//! use miette::{Diagnostic, SourceSpan};
192//! use thiserror::Error;
193//!
194//! #[derive(Error, Diagnostic, Debug)]
195//! pub enum MyLibError {
196//!     #[error(transparent)]
197//!     #[diagnostic(code(my_lib::io_error))]
198//!     IoError(#[from] std::io::Error),
199//!
200//!     #[error("Oops it blew up")]
201//!     #[diagnostic(code(my_lib::bad_code))]
202//!     BadThingHappened,
203//!
204//!     #[error(transparent)]
205//!     // Use `#[diagnostic(transparent)]` to wrap another [`Diagnostic`]. You won't see labels otherwise
206//!     #[diagnostic(transparent)]
207//!     AnotherError(#[from] AnotherError),
208//! }
209//!
210//! #[derive(Error, Diagnostic, Debug)]
211//! #[error("another error")]
212//! pub struct AnotherError {
213//!    #[label("here")]
214//!    pub at: SourceSpan
215//! }
216//! ```
217//!
218//! Then, return this error type from all your fallible public APIs. It's a best
219//! practice to wrap any "external" error types in your error `enum` instead of
220//! using something like [`Report`] in a library.
221//!
222//! ### ... in application code
223//!
224//! Application code tends to work a little differently than libraries. You
225//! don't always need or care to define dedicated error wrappers for errors
226//! coming from external libraries and tools.
227//!
228//! For this situation, `miette` includes two tools: [`Report`] and
229//! [`IntoDiagnostic`]. They work in tandem to make it easy to convert regular
230//! `std::error::Error`s into [`Diagnostic`]s. Additionally, there's a
231//! [`Result`] type alias that you can use to be more terse.
232//!
233//! When dealing with non-`Diagnostic` types, you'll want to
234//! `.into_diagnostic()` them:
235//!
236//! ```rust
237//! // my_app/lib/my_internal_file.rs
238//! use miette::{IntoDiagnostic, Result};
239//! use semver::Version;
240//!
241//! pub fn some_tool() -> Result<Version> {
242//!     "1.2.x".parse().into_diagnostic()
243//! }
244//! ```
245//!
246//! `miette` also includes an `anyhow`/`eyre`-style `Context`/`WrapErr` traits
247//! that you can import to add ad-hoc context messages to your `Diagnostic`s, as
248//! well, though you'll still need to use `.into_diagnostic()` to make use of
249//! it:
250//!
251//! ```rust
252//! // my_app/lib/my_internal_file.rs
253//! use miette::{IntoDiagnostic, Result, WrapErr};
254//! use semver::Version;
255//!
256//! pub fn some_tool() -> Result<Version> {
257//!     "1.2.x"
258//!         .parse()
259//!         .into_diagnostic()
260//!         .wrap_err("Parsing this tool's semver version failed.")
261//! }
262//! ```
263//!
264//! To construct your own simple adhoc error use the [miette!] macro:
265//! ```rust
266//! // my_app/lib/my_internal_file.rs
267//! use miette::{miette, Result};
268//! use semver::Version;
269//!
270//! pub fn some_tool() -> Result<Version> {
271//!     let version = "1.2.x";
272//!     version
273//!         .parse()
274//!         .map_err(|_| miette!("Invalid version {}", version))
275//! }
276//! ```
277//! There are also similar [bail!] and [ensure!] macros.
278//!
279//! ### ... in `main()`
280//!
281//! `main()` is just like any other part of your application-internal code. Use
282//! `Result` as your return value, and it will pretty-print your diagnostics
283//! automatically.
284//!
285//! > **NOTE:** You must enable the `"fancy"` crate feature to get fancy report
286//! > output like in the screenshots here.** You should only do this in your
287//! > toplevel crate, as the fancy feature pulls in a number of dependencies that
288//! > libraries and such might not want.
289//!
290//! ```rust
291//! use miette::{IntoDiagnostic, Result};
292//! use semver::Version;
293//!
294//! fn pretend_this_is_main() -> Result<()> {
295//!     let version: Version = "1.2.x".parse().into_diagnostic()?;
296//!     println!("{}", version);
297//!     Ok(())
298//! }
299//! ```
300//!
301//! Please note: in order to get fancy diagnostic rendering with all the pretty
302//! colors and arrows, you should install `miette` with the `fancy` feature
303//! enabled:
304//!
305//! ```toml
306//! miette = { version = "X.Y.Z", features = ["fancy"] }
307//! ```
308//!
309//! Another way to display a diagnostic is by printing them using the debug formatter.
310//! This is, in fact, what returning diagnostics from main ends up doing.
311//! To do it yourself, you can write the following:
312//!
313//! ```rust
314//! use miette::{IntoDiagnostic, Result};
315//! use semver::Version;
316//!
317//! fn just_a_random_function() {
318//!     let version_result: Result<Version> = "1.2.x".parse().into_diagnostic();
319//!     match version_result {
320//!         Err(e) => println!("{:?}", e),
321//!         Ok(version) => println!("{}", version),
322//!     }
323//! }
324//! ```
325//!
326//! ### ... diagnostic code URLs
327//!
328//! `miette` supports providing a URL for individual diagnostics. This URL will
329//! be displayed as an actual link in supported terminals, like so:
330//!
331//! <img
332//! src="https://raw.githubusercontent.com/zkat/miette/main/images/code_linking.png"
333//! alt=" Example showing the graphical report printer for miette
334//! pretty-printing an error code. The code is underlined and followed by text
335//! saying to 'click here'. A hover tooltip shows a full-fledged URL that can be
336//! Ctrl+Clicked to open in a browser.
337//! \
338//! This feature is also available in the narratable printer. It will add a line
339//! after printing the error code showing a plain URL that you can visit.
340//! ">
341//!
342//! To use this, you can add a `url()` sub-param to your `#[diagnostic]`
343//! attribute:
344//!
345//! ```rust
346//! use miette::Diagnostic;
347//! use thiserror::Error;
348//!
349//! #[derive(Error, Diagnostic, Debug)]
350//! #[error("kaboom")]
351//! #[diagnostic(
352//!     code(my_app::my_error),
353//!     // You can do formatting!
354//!     url("https://my_website.com/error_codes#{}", self.code().unwrap())
355//! )]
356//! struct MyErr;
357//! ```
358//!
359//! Additionally, if you're developing a library and your error type is exported
360//! from your crate's top level, you can use a special `url(docsrs)` option
361//! instead of manually constructing the URL. This will automatically create a
362//! link to this diagnostic on `docs.rs`, so folks can just go straight to your
363//! (very high quality and detailed!) documentation on this diagnostic:
364//!
365//! ```rust
366//! use miette::Diagnostic;
367//! use thiserror::Error;
368//!
369//! #[derive(Error, Diagnostic, Debug)]
370//! #[diagnostic(
371//!     code(my_app::my_error),
372//!     // Will link users to https://docs.rs/my_crate/0.0.0/my_crate/struct.MyErr.html
373//!     url(docsrs)
374//! )]
375//! #[error("kaboom")]
376//! struct MyErr;
377//! ```
378//!
379//! ### ... snippets
380//!
381//! Along with its general error handling and reporting features, `miette` also
382//! includes facilities for adding error spans/annotations/labels to your
383//! output. This can be very useful when an error is syntax-related, but you can
384//! even use it to print out sections of your own source code!
385//!
386//! To achieve this, `miette` defines its own lightweight [`SourceSpan`] type.
387//! This is a basic byte-offset and length into an associated [`SourceCode`]
388//! and, along with the latter, gives `miette` all the information it needs to
389//! pretty-print some snippets! You can also use your own `Into<SourceSpan>`
390//! types as label spans.
391//!
392//! The easiest way to define errors like this is to use the
393//! `derive(Diagnostic)` macro:
394//!
395//! ```rust
396//! use miette::{Diagnostic, SourceSpan};
397//! use thiserror::Error;
398//!
399//! #[derive(Diagnostic, Debug, Error)]
400//! #[error("oops")]
401//! #[diagnostic(code(my_lib::random_error))]
402//! pub struct MyErrorType {
403//!     // The `Source` that miette will use.
404//!     #[source_code]
405//!     src: String,
406//!
407//!     // This will underline/mark the specific code inside the larger
408//!     // snippet context.
409//!     #[label = "This is the highlight"]
410//!     err_span: SourceSpan,
411//!
412//!     // You can add as many labels as you want.
413//!     // They'll be rendered sequentially.
414//!     #[label("This is bad")]
415//!     snip2: (usize, usize), // `(usize, usize)` is `Into<SourceSpan>`!
416//!
417//!     // Snippets can be optional, by using Option:
418//!     #[label("some text")]
419//!     snip3: Option<SourceSpan>,
420//!
421//!     // with or without label text
422//!     #[label]
423//!     snip4: Option<SourceSpan>,
424//! }
425//! ```
426//!
427//! ### ... help text
428//! `miette` provides two facilities for supplying help text for your errors:
429//!
430//! The first is the `#[help()]` format attribute that applies to structs or
431//! enum variants:
432//!
433//! ```rust
434//! use miette::Diagnostic;
435//! use thiserror::Error;
436//!
437//! #[derive(Debug, Diagnostic, Error)]
438//! #[error("welp")]
439//! #[diagnostic(help("try doing this instead"))]
440//! struct Foo;
441//! ```
442//!
443//! The other is by programmatically supplying the help text as a field to
444//! your diagnostic:
445//!
446//! ```rust
447//! use miette::Diagnostic;
448//! use thiserror::Error;
449//!
450//! #[derive(Debug, Diagnostic, Error)]
451//! #[error("welp")]
452//! #[diagnostic()]
453//! struct Foo {
454//!     #[help]
455//!     advice: Option<String>, // Can also just be `String`
456//! }
457//!
458//! let err = Foo {
459//!     advice: Some("try doing this instead".to_string()),
460//! };
461//! ```
462//!
463//! ### ... severity level
464//! `miette` provides a way to set the severity level of a diagnostic.
465//!
466//! ```rust
467//! use miette::Diagnostic;
468//! use thiserror::Error;
469//!
470//! #[derive(Debug, Diagnostic, Error)]
471//! #[error("welp")]
472//! #[diagnostic(severity(Warning))]
473//! struct Foo;
474//! ```
475//!
476//! ### ... multiple related errors
477//!
478//! `miette` supports collecting multiple errors into a single diagnostic, and
479//! printing them all together nicely.
480//!
481//! To do so, use the `#[related]` tag on any `IntoIter` field in your
482//! `Diagnostic` type:
483//!
484//! ```rust
485//! use miette::Diagnostic;
486//! use thiserror::Error;
487//!
488//! #[derive(Debug, Error, Diagnostic)]
489//! #[error("oops")]
490//! struct MyError {
491//!     #[related]
492//!     others: Vec<MyError>,
493//! }
494//! ```
495//!
496//! ### ... delayed source code
497//!
498//! Sometimes it makes sense to add source code to the error message later.
499//! One option is to use [`with_source_code()`](Report::with_source_code)
500//! method for that:
501//!
502//! ```rust,no_run
503//! use miette::{Diagnostic, SourceSpan};
504//! use thiserror::Error;
505//!
506//! #[derive(Diagnostic, Debug, Error)]
507//! #[error("oops")]
508//! #[diagnostic()]
509//! pub struct MyErrorType {
510//!     // Note: label but no source code
511//!     #[label]
512//!     err_span: SourceSpan,
513//! }
514//!
515//! fn do_something() -> miette::Result<()> {
516//!     // This function emits actual error with label
517//!     return Err(MyErrorType {
518//!         err_span: (7..11).into(),
519//!     })?;
520//! }
521//!
522//! fn main() -> miette::Result<()> {
523//!     do_something().map_err(|error| {
524//!         // And this code provides the source code for inner error
525//!         error.with_source_code(String::from("source code"))
526//!     })
527//! }
528//! ```
529//!
530//! Also source code can be provided by a wrapper type. This is especially
531//! useful in combination with `related`, when multiple errors should be
532//! emitted at the same time:
533//!
534//! ```rust,no_run
535//! use miette::{Diagnostic, Report, SourceSpan};
536//! use thiserror::Error;
537//!
538//! #[derive(Diagnostic, Debug, Error)]
539//! #[error("oops")]
540//! #[diagnostic()]
541//! pub struct InnerError {
542//!     // Note: label but no source code
543//!     #[label]
544//!     err_span: SourceSpan,
545//! }
546//!
547//! #[derive(Diagnostic, Debug, Error)]
548//! #[error("oops: multiple errors")]
549//! #[diagnostic()]
550//! pub struct MultiError {
551//!     // Note source code by no labels
552//!     #[source_code]
553//!     source_code: String,
554//!     // The source code above is used for these errors
555//!     #[related]
556//!     related: Vec<InnerError>,
557//! }
558//!
559//! fn do_something() -> Result<(), Vec<InnerError>> {
560//!     Err(vec![
561//!         InnerError {
562//!             err_span: (0..6).into(),
563//!         },
564//!         InnerError {
565//!             err_span: (7..11).into(),
566//!         },
567//!     ])
568//! }
569//!
570//! fn main() -> miette::Result<()> {
571//!     do_something().map_err(|err_list| MultiError {
572//!         source_code: "source code".into(),
573//!         related: err_list,
574//!     })?;
575//!     Ok(())
576//! }
577//! ```
578//!
579//! ### ... Diagnostic-based error sources.
580//!
581//! When one uses the `#[source]` attribute on a field, that usually comes
582//! from `thiserror`, and implements a method for
583//! [`std::error::Error::source`]. This works in many cases, but it's lossy:
584//! if the source of the diagnostic is a diagnostic itself, the source will
585//! simply be treated as an `std::error::Error`.
586//!
587//! While this has no effect on the existing _reporters_, since they don't use
588//! that information right now, APIs who might want this information will have
589//! no access to it.
590//!
591//! If it's important for you for this information to be available to users,
592//! you can use `#[diagnostic_source]` alongside `#[source]`. Not that you
593//! will likely want to use _both_:
594//!
595//! ```rust
596//! use miette::Diagnostic;
597//! use thiserror::Error;
598//!
599//! #[derive(Debug, Diagnostic, Error)]
600//! #[error("MyError")]
601//! struct MyError {
602//!     #[source]
603//!     #[diagnostic_source]
604//!     the_cause: OtherError,
605//! }
606//!
607//! #[derive(Debug, Diagnostic, Error)]
608//! #[error("OtherError")]
609//! struct OtherError;
610//! ```
611//!
612//! ### ... handler options
613//!
614//! [`MietteHandler`] is the default handler, and is very customizable. In
615//! most cases, you can simply use [`MietteHandlerOpts`] to tweak its behavior
616//! instead of falling back to your own custom handler.
617//!
618//! Usage is like so:
619//!
620//! ```rust,ignore
621//! miette::set_hook(Box::new(|_| {
622//!     Box::new(
623//!         miette::MietteHandlerOpts::new()
624//!             .terminal_links(true)
625//!             .unicode(false)
626//!             .context_lines(3)
627//!             .tab_width(4)
628//!             .break_words(true)
629//!             .build(),
630//!     )
631//! }))
632//!
633//! ```
634//!
635//! See the docs for [`MietteHandlerOpts`] for more details on what you can
636//! customize!
637//!
638//! ### ... dynamic diagnostics
639//!
640//! If you...
641//! - ...don't know all the possible errors upfront
642//! - ...need to serialize/deserialize errors
643//!
644//! then you may want to use [`miette!`], [`diagnostic!`] macros or
645//! [`MietteDiagnostic`] directly to create diagnostic on the fly.
646//!
647//! ```rust,ignore
648//! # use miette::{miette, LabeledSpan, Report};
649//!
650//! let source = "2 + 2 * 2 = 8".to_string();
651//! let report = miette!(
652//!   labels = vec![
653//!       LabeledSpan::at(12..13, "this should be 6"),
654//!   ],
655//!   help = "'*' has greater precedence than '+'",
656//!   "Wrong answer"
657//! ).with_source_code(source);
658//! println!("{:?}", report)
659//! ```
660//!
661//! ### ... collection of labels
662//!
663//! When the number of labels is unknown, you can use a collection of `SourceSpan`
664//! (or any type convertible into `SourceSpan`). For this, add the `collection`
665//! parameter to `label` and use any type than can be iterated over for the field.
666//!
667//! ```rust,ignore
668//! #[derive(Debug, Diagnostic, Error)]
669//! #[error("oops!")]
670//! struct MyError {
671//!     #[label("main issue")]
672//!     primary_span: SourceSpan,
673//!
674//!     #[label(collection, "related to this")]
675//!     other_spans: Vec<Range<usize>>,
676//! }
677//!
678//! let report: miette::Report = MyError {
679//!     primary_span: (6, 9).into(),
680//!     other_spans: vec![19..26, 30..41],
681//! }.into();
682//!
683//! println!("{:?}", report.with_source_code("About something or another or yet another ...".to_string()));
684//! ```
685//!
686//! A collection can also be of `LabeledSpan` if you want to have different text
687//! for different labels. Labels with no text will use the one from the `label`
688//! attribute
689//!
690//! ```rust,ignore
691//! #[derive(Debug, Diagnostic, Error)]
692//! #[error("oops!")]
693//! struct MyError {
694//!     #[label("main issue")]
695//!     primary_span: SourceSpan,
696//!
697//!     #[label(collection, "related to this")]
698//!     other_spans: Vec<LabeledSpan>, // LabeledSpan
699//! }
700//!
701//! let report: miette::Report = MyError {
702//!     primary_span: (6, 9).into(),
703//!     other_spans: vec![
704//!         LabeledSpan::new(None, 19, 7), // Use default text `related to this`
705//!         LabeledSpan::new(Some("and also this".to_string()), 30, 11), // Use specific text
706//!     ],
707//! }.into();
708//!
709//! println!("{:?}", report.with_source_code("About something or another or yet another ...".to_string()));
710//! ```
711//!
712//! ## MSRV
713//!
714//! This crate requires rustc 1.70.0 or later.
715//!
716//! ## Acknowledgements
717//!
718//! `miette` was not developed in a void. It owes enormous credit to various
719//! other projects and their authors:
720//!
721//! - [`anyhow`](http://crates.io/crates/anyhow) and [`color-eyre`](https://crates.io/crates/color-eyre):
722//!   these two enormously influential error handling libraries have pushed
723//!   forward the experience of application-level error handling and error
724//!   reporting. `miette`'s `Report` type is an attempt at a very very rough
725//!   version of their `Report` types.
726//! - [`thiserror`](https://crates.io/crates/thiserror) for setting the standard
727//!   for library-level error definitions, and for being the inspiration behind
728//!   `miette`'s derive macro.
729//! - `rustc` and [@estebank](https://github.com/estebank) for their
730//!   state-of-the-art work in compiler diagnostics.
731//! - [`ariadne`](https://crates.io/crates/ariadne) for pushing forward how
732//!   _pretty_ these diagnostics can really look!
733//!
734//! ## License
735//!
736//! `miette` is released to the Rust community under the [Apache license
737//! 2.0](./LICENSE).
738//!
739//! It also includes code taken from [`eyre`](https://github.com/yaahc/eyre),
740//! and some from [`thiserror`](https://github.com/dtolnay/thiserror), also
741//! under the Apache License. Some code is taken from
742//! [`ariadne`](https://github.com/zesterer/ariadne), which is MIT licensed.
743//!
744//! [`miette!`]: https://docs.rs/miette/latest/miette/macro.miette.html
745//! [`diagnostic!`]: https://docs.rs/miette/latest/miette/macro.diagnostic.html
746//! [`std::error::Error`]: https://doc.rust-lang.org/nightly/std/error/trait.Error.html
747//! [`Diagnostic`]: https://docs.rs/miette/latest/miette/trait.Diagnostic.html
748//! [`IntoDiagnostic`]: https://docs.rs/miette/latest/miette/trait.IntoDiagnostic.html
749//! [`MietteHandlerOpts`]: https://docs.rs/miette/latest/miette/struct.MietteHandlerOpts.html
750//! [`MietteHandler`]: https://docs.rs/miette/latest/miette/struct.MietteHandler.html
751//! [`MietteDiagnostic`]: https://docs.rs/miette/latest/miette/struct.MietteDiagnostic.html
752//! [`Report`]: https://docs.rs/miette/latest/miette/struct.Report.html
753//! [`ReportHandler`]: https://docs.rs/miette/latest/miette/trait.ReportHandler.html
754//! [`Result`]: https://docs.rs/miette/latest/miette/type.Result.html
755//! [`SourceCode`]: https://docs.rs/miette/latest/miette/trait.SourceCode.html
756//! [`SourceSpan`]: https://docs.rs/miette/latest/miette/struct.SourceSpan.html
757pub use error::*;
758pub use eyreish::*;
759#[cfg(feature = "fancy-base")]
760pub use handler::*;
761pub use handlers::*;
762pub use miette_diagnostic::*;
763pub use named_source::*;
764#[cfg(feature = "derive")]
765pub use oxc_miette_derive::*;
766#[cfg(feature = "fancy")]
767pub use panic::*;
768pub use protocol::*;
769
770mod chain;
771mod diagnostic_chain;
772mod error;
773mod eyreish;
774#[cfg(feature = "fancy-base")]
775mod handler;
776mod handlers;
777#[doc(hidden)]
778pub mod macro_helpers;
779mod miette_diagnostic;
780mod named_source;
781#[cfg(feature = "fancy")]
782mod panic;
783mod protocol;
784mod source_impls;