Skip to content

Commit c61064c

Browse files
committed
better error display
1 parent c03651d commit c61064c

4 files changed

Lines changed: 105 additions & 94 deletions

File tree

src/build/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ fn build_from_sources_impl(
647647
module_results.push(ModuleResult {
648648
path: pm.path.clone(),
649649
module_name: pm.module_name.clone(),
650+
650651
type_errors: vec![],
651652
cached: true,
652653
});
@@ -723,6 +724,7 @@ fn build_from_sources_impl(
723724
module_results.push(ModuleResult {
724725
path: pm.path.clone(),
725726
module_name: pm.module_name.clone(),
727+
726728
type_errors: result.errors,
727729
cached: false,
728730
});
@@ -847,6 +849,7 @@ fn build_from_sources_impl(
847849
module_results.push(ModuleResult {
848850
path: pm.path.clone(),
849851
module_name: pm.module_name.clone(),
852+
850853
type_errors: result.errors,
851854
cached: false,
852855
});

src/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,22 @@ fn main() {
8888
}
8989

9090
for module in &result.modules {
91+
if module.type_errors.is_empty() {
92+
continue;
93+
}
94+
let source = std::fs::read_to_string(&module.path).unwrap_or_default();
9195
for err in &module.type_errors {
92-
error_messages.push(format!("{}: {err}", module.module_name));
96+
let span = err.span();
97+
let location = match span.to_pos(&source) {
98+
Some((start, end)) => format!(
99+
"{}:{}:{} - {}:{}",
100+
module.path.display(),
101+
start.line, start.column,
102+
end.line, end.column
103+
),
104+
None => format!("{}", module.path.display()),
105+
};
106+
error_messages.push(format!("{location}: {err}"));
93107
}
94108
}
95109

0 commit comments

Comments
 (0)