Skip to content

Commit 14d2157

Browse files
committed
Unescape parser errors
1 parent ba654a8 commit 14d2157

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

crates/formality-types/src/parse.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ where
4343
let (t, remainder) = match T::parse(&scope, text) {
4444
Ok(v) => v,
4545
Err(errors) => {
46-
anyhow::bail!("failed to parse {text:?}: {errors:#?}");
46+
let mut err = anyhow::anyhow!("failed to parse {text}");
47+
for error in errors {
48+
err = err.context(error.text.to_owned()).context(error.message);
49+
}
50+
return Err(err);
4751
}
4852
};
4953
if !skip_whitespace(remainder).is_empty() {

tests/ui/parser.stderr

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
Error: failed to parse "[\n crate Foo { \n trait Baz<> where [ cake ] {}\n }\n]\n": {
2-
ParseError {
3-
text: " ] {}\n }\n]\n",
4-
message: "expected `:`",
5-
},
6-
}
1+
Error: expected `:`
2+
3+
Caused by:
4+
0: ] {}
5+
}
6+
]
7+
8+
1: failed to parse [
9+
crate Foo {
10+
trait Baz<> where [ cake ] {}
11+
}
12+
]
13+

0 commit comments

Comments
 (0)