luaur_analyze_cli/functions/
report_error.rs1use crate::enums::report_format::ReportFormat;
2use crate::functions::report::report;
3use luaur_analysis::functions::to_string_error_alt_k::to_string_type_error_type_error_to_string_options;
4use luaur_analysis::records::file_resolver::FileResolver;
5use luaur_analysis::records::frontend::Frontend;
6use luaur_analysis::records::syntax_error::SyntaxError;
7use luaur_analysis::records::type_error::TypeError;
8use luaur_analysis::records::type_error_to_string_options::TypeErrorToStringOptions;
9use luaur_analysis::type_aliases::type_error_data::TypeErrorDataMember;
10
11pub fn report_error(frontend: &Frontend, format: ReportFormat, error: &TypeError) {
14 let human_readable_name = unsafe {
16 FileResolver::get_human_readable_module_name(frontend.file_resolver, &error.module_name)
17 };
18
19 if let Some(syntax_error) = SyntaxError::get_if(&error.data) {
21 report(
22 format,
23 &human_readable_name,
24 &error.location,
25 "SyntaxError",
26 syntax_error.message(),
27 );
28 } else {
29 let message = to_string_type_error_type_error_to_string_options(
30 error,
31 TypeErrorToStringOptions {
32 file_resolver: frontend.file_resolver,
33 },
34 );
35 report(
36 format,
37 &human_readable_name,
38 &error.location,
39 "TypeError",
40 &message,
41 );
42 }
43}