Skip to content

Commit 13ca945

Browse files
authored
Replace miette with ariadne (#712)
Closes #602 Some docs still mention miette and link to an example, but they already use a perma-link to an old commit.
1 parent 2f4fabe commit 13ca945

File tree

3 files changed

+11
-27
lines changed

3 files changed

+11
-27
lines changed

crates/apollo-compiler/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ uuid = { version = "1.4", features = ["serde", "v4", "js"] }
3434
anyhow = "1.0"
3535
criterion = "0.5.1"
3636
expect-test = "1.4"
37-
miette = "5.0"
3837
notify = "6.0.0"
3938
pretty_assertions = "1.3.0"
4039
serial_test = "2.0.0"

crates/apollo-parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ rowan = "0.15.5"
2222
thiserror = "1.0.30"
2323

2424
[dev-dependencies]
25+
ariadne = "0.3.0"
2526
indexmap = "2.0.0"
26-
miette = { version = "3.2.0", features = ["fancy"] }
2727
apollo-encoder = { path = "../apollo-encoder", version = "0.8.0", features = [
2828
"apollo-parser",
2929
] }
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
/// This example describes how to use `apollo-parser` with
2-
/// [`miette`](https://docs.rs/miette/3.2.0/miette) diagnostic library.
3-
///
4-
///
2+
/// [`ariadne`](https://docs.rs/ariadne/0.3.0/ariadne) diagnostic library.
53
use std::{fs, path::Path};
64

75
use apollo_parser::{cst, Parser};
8-
use miette::{Diagnostic, NamedSource, Report, SourceSpan};
9-
use thiserror::Error;
10-
11-
// If your application is using a bunch of other thiserror errors,
12-
// `ApolloParserError` can live within that enum and be responsible for just
13-
// `apollo-parser` errors. It should work really nicely together!
14-
#[derive(Error, Debug, Diagnostic)]
15-
#[error("{}", self.ty)]
16-
#[diagnostic(code("apollo-parser parsing error."))]
17-
struct ApolloParserError {
18-
ty: String,
19-
#[source_code]
20-
src: NamedSource,
21-
#[label("{}", self.ty)]
22-
span: SourceSpan,
23-
}
6+
use ariadne::{Label, Report, ReportKind, Source};
247

258
fn parse_schema() -> cst::Document {
269
let file = Path::new("crates/apollo-parser/examples/schema_with_errors.graphql");
@@ -41,12 +24,14 @@ fn parse_schema() -> cst::Document {
4124
for err in cst.errors() {
4225
// We need to create a report and print that individually, as the error
4326
// slice can have many errors.
44-
let err = Report::new(ApolloParserError {
45-
src: NamedSource::new(file_name, src.clone()),
46-
span: (err.index(), err.data().len()).into(), // (offset, length of error token)
47-
ty: err.message().into(),
48-
});
49-
println!("{err:?}");
27+
let start = err.index();
28+
let end = start + err.data().len();
29+
Report::build(ReportKind::Error, file_name, start)
30+
.with_message(err.message())
31+
.with_label(Label::new((file_name, start..end)).with_message(err.message()))
32+
.finish()
33+
.eprint((file_name, Source::from(&src)))
34+
.unwrap();
5035
}
5136

5237
cst.document()

0 commit comments

Comments
 (0)