mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge pull request #6257 from roc-lang/fix-unknown-dot-roc
Replace UNKNOWN.roc in reports with real filename
This commit is contained in:
commit
4952f5e1d0
3 changed files with 68 additions and 47 deletions
|
@ -684,6 +684,7 @@ impl MakeSpecializationsPass {
|
|||
struct State<'a> {
|
||||
pub root_id: ModuleId,
|
||||
pub root_subs: Option<Subs>,
|
||||
pub root_path: PathBuf,
|
||||
pub cache_dir: PathBuf,
|
||||
/// If the root is an app module, the shorthand specified in its header's `to` field
|
||||
pub opt_platform_shorthand: Option<&'a str>,
|
||||
|
@ -752,6 +753,7 @@ impl<'a> State<'a> {
|
|||
|
||||
fn new(
|
||||
root_id: ModuleId,
|
||||
root_path: PathBuf,
|
||||
opt_platform_shorthand: Option<&'a str>,
|
||||
target_info: TargetInfo,
|
||||
function_kind: FunctionKind,
|
||||
|
@ -770,6 +772,7 @@ impl<'a> State<'a> {
|
|||
|
||||
Self {
|
||||
root_id,
|
||||
root_path,
|
||||
root_subs: None,
|
||||
opt_platform_shorthand,
|
||||
cache_dir,
|
||||
|
@ -1077,8 +1080,9 @@ pub struct LoadStart<'a> {
|
|||
arc_modules: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||
ident_ids_by_module: SharedIdentIdsByModule,
|
||||
root_id: ModuleId,
|
||||
opt_platform_shorthand: Option<&'a str>,
|
||||
root_path: PathBuf,
|
||||
root_msg: Msg<'a>,
|
||||
opt_platform_shorthand: Option<&'a str>,
|
||||
src_dir: PathBuf,
|
||||
}
|
||||
|
||||
|
@ -1101,7 +1105,7 @@ impl<'a> LoadStart<'a> {
|
|||
|
||||
let res_loaded = load_filename(
|
||||
arena,
|
||||
filename,
|
||||
filename.clone(),
|
||||
true,
|
||||
None,
|
||||
None,
|
||||
|
@ -1136,6 +1140,7 @@ impl<'a> LoadStart<'a> {
|
|||
ident_ids_by_module,
|
||||
src_dir,
|
||||
root_id: header_output.module_id,
|
||||
root_path: filename,
|
||||
root_msg: header_output.msg,
|
||||
opt_platform_shorthand: header_output.opt_platform_shorthand,
|
||||
})
|
||||
|
@ -1162,7 +1167,7 @@ impl<'a> LoadStart<'a> {
|
|||
|
||||
let header_output = load_from_str(
|
||||
arena,
|
||||
filename,
|
||||
filename.clone(),
|
||||
src,
|
||||
Arc::clone(&arc_modules),
|
||||
Arc::clone(&ident_ids_by_module),
|
||||
|
@ -1178,6 +1183,7 @@ impl<'a> LoadStart<'a> {
|
|||
src_dir,
|
||||
ident_ids_by_module,
|
||||
root_id,
|
||||
root_path: filename,
|
||||
root_msg,
|
||||
opt_platform_shorthand: opt_platform_id,
|
||||
})
|
||||
|
@ -1352,6 +1358,7 @@ pub fn load_single_threaded<'a>(
|
|||
arc_modules,
|
||||
ident_ids_by_module,
|
||||
root_id,
|
||||
root_path,
|
||||
root_msg,
|
||||
src_dir,
|
||||
opt_platform_shorthand,
|
||||
|
@ -1367,6 +1374,7 @@ pub fn load_single_threaded<'a>(
|
|||
let number_of_workers = 1;
|
||||
let mut state = State::new(
|
||||
root_id,
|
||||
root_path,
|
||||
opt_platform_shorthand,
|
||||
target_info,
|
||||
function_kind,
|
||||
|
@ -1503,7 +1511,7 @@ fn state_thread_step<'a>(
|
|||
Ok(ControlFlow::Break(LoadResult::Monomorphized(monomorphized)))
|
||||
}
|
||||
Msg::FailedToReadFile { filename, error } => {
|
||||
let buf = to_file_problem_report_string(&filename, error);
|
||||
let buf = to_file_problem_report_string(filename, error);
|
||||
Err(LoadingProblem::FormattedReport(buf))
|
||||
}
|
||||
|
||||
|
@ -1654,7 +1662,7 @@ pub fn report_loading_problem(
|
|||
}
|
||||
LoadingProblem::FormattedReport(report) => report,
|
||||
LoadingProblem::FileProblem { filename, error } => {
|
||||
to_file_problem_report_string(&filename, error)
|
||||
to_file_problem_report_string(filename, error)
|
||||
}
|
||||
err => todo!("Loading error: {:?}", err),
|
||||
}
|
||||
|
@ -1677,6 +1685,7 @@ fn load_multi_threaded<'a>(
|
|||
arc_modules,
|
||||
ident_ids_by_module,
|
||||
root_id,
|
||||
root_path,
|
||||
root_msg,
|
||||
src_dir,
|
||||
opt_platform_shorthand,
|
||||
|
@ -1707,6 +1716,7 @@ fn load_multi_threaded<'a>(
|
|||
|
||||
let mut state = State::new(
|
||||
root_id,
|
||||
root_path,
|
||||
opt_platform_shorthand,
|
||||
target_info,
|
||||
function_kind,
|
||||
|
@ -2238,6 +2248,7 @@ fn update<'a>(
|
|||
let buf = to_https_problem_report_string(
|
||||
url,
|
||||
Problem::InvalidUrl(url_err),
|
||||
header.module_path,
|
||||
);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
}
|
||||
|
@ -3159,7 +3170,7 @@ fn finish_specialization<'a>(
|
|||
}
|
||||
Valid(To::NewPackage(p_or_p)) => PathBuf::from(p_or_p.as_str()),
|
||||
other => {
|
||||
let buf = to_missing_platform_report(state.root_id, other);
|
||||
let buf = report_cannot_run(state.root_id, state.root_path, other);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
}
|
||||
};
|
||||
|
@ -3513,9 +3524,7 @@ fn load_builtin_module_help<'a>(
|
|||
) -> (HeaderInfo<'a>, roc_parse::state::State<'a>) {
|
||||
let is_root_module = false;
|
||||
let opt_shorthand = None;
|
||||
|
||||
let filename = PathBuf::from(filename);
|
||||
|
||||
let parse_state = roc_parse::state::State::new(src_bytes.as_bytes());
|
||||
let parsed = roc_parse::module::parse_header(arena, parse_state.clone());
|
||||
|
||||
|
@ -3968,6 +3977,7 @@ fn parse_header<'a>(
|
|||
module_timing,
|
||||
)?;
|
||||
|
||||
let filename = resolved_header.module_path.clone();
|
||||
let mut messages = Vec::with_capacity(packages.len() + 1);
|
||||
|
||||
// It's important that the app header is first in the list!
|
||||
|
@ -3982,6 +3992,7 @@ fn parse_header<'a>(
|
|||
module_id,
|
||||
module_ids,
|
||||
ident_ids_by_module,
|
||||
filename,
|
||||
);
|
||||
|
||||
// Look at the app module's `to` keyword to determine which package was the platform.
|
||||
|
@ -4084,6 +4095,7 @@ fn load_packages<'a>(
|
|||
module_id: ModuleId,
|
||||
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||
ident_ids_by_module: SharedIdentIdsByModule,
|
||||
filename: PathBuf,
|
||||
) {
|
||||
// Load all the packages
|
||||
for Loc { value: entry, .. } in packages.iter() {
|
||||
|
@ -4121,7 +4133,7 @@ fn load_packages<'a>(
|
|||
}
|
||||
}
|
||||
Err(problem) => {
|
||||
let buf = to_https_problem_report_string(src, problem);
|
||||
let buf = to_https_problem_report_string(src, problem, filename);
|
||||
|
||||
load_messages.push(Msg::FailedToLoad(LoadingProblem::FormattedReport(buf)));
|
||||
return;
|
||||
|
@ -6581,7 +6593,11 @@ fn to_parse_problem_report<'a>(
|
|||
buf
|
||||
}
|
||||
|
||||
fn to_missing_platform_report(module_id: ModuleId, other: &PlatformPath) -> String {
|
||||
fn report_cannot_run(
|
||||
module_id: ModuleId,
|
||||
filename: PathBuf,
|
||||
platform_path: &PlatformPath,
|
||||
) -> String {
|
||||
use roc_reporting::report::{Report, RocDocAllocator, DEFAULT_PALETTE};
|
||||
use ven_pretty::DocAllocator;
|
||||
use PlatformPath::*;
|
||||
|
@ -6591,20 +6607,20 @@ fn to_missing_platform_report(module_id: ModuleId, other: &PlatformPath) -> Stri
|
|||
let alloc = RocDocAllocator::new(&[], module_id, &interns);
|
||||
|
||||
let report = {
|
||||
match other {
|
||||
match platform_path {
|
||||
Valid(_) => unreachable!(),
|
||||
NotSpecified => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow("I could not find a platform based on your input file."),
|
||||
alloc.reflow(r"Does the module header contain an entry that looks like this:"),
|
||||
alloc.reflow(r"Does the module header have an entry that looks like this?"),
|
||||
alloc
|
||||
.parser_suggestion(" packages { pf: \"platform\" }")
|
||||
.parser_suggestion("packages { blah: \"…path or URL to platform…\" }")
|
||||
.indent(4),
|
||||
alloc.reflow("See also TODO."),
|
||||
alloc.reflow("Tip: The following part of the tutorial has an example of specifying a platform:\n\n<https://www.roc-lang.org/tutorial#building-an-application>"),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "NO PLATFORM".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
|
@ -6619,7 +6635,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: &PlatformPath) -> Stri
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "NO PLATFORM".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
|
@ -6634,7 +6650,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: &PlatformPath) -> Stri
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "NO PLATFORM".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
|
@ -6649,7 +6665,7 @@ fn to_missing_platform_report(module_id: ModuleId, other: &PlatformPath) -> Stri
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "NO PLATFORM".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
|
|
|
@ -1090,7 +1090,7 @@ pub fn can_problem<'b>(
|
|||
title = "OVERAPPLIED CRASH".to_string();
|
||||
}
|
||||
Problem::FileProblem { filename, error } => {
|
||||
let report = to_file_problem_report(alloc, &filename, error);
|
||||
let report = to_file_problem_report(alloc, filename, error);
|
||||
doc = report.doc;
|
||||
title = report.title;
|
||||
}
|
||||
|
|
|
@ -1101,7 +1101,11 @@ where
|
|||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn to_https_problem_report_string(url: &str, https_problem: Problem) -> String {
|
||||
pub fn to_https_problem_report_string(
|
||||
url: &str,
|
||||
https_problem: Problem,
|
||||
filename: PathBuf,
|
||||
) -> String {
|
||||
let src_lines: Vec<&str> = Vec::new();
|
||||
|
||||
let mut module_ids = ModuleIds::default();
|
||||
|
@ -1115,7 +1119,7 @@ pub fn to_https_problem_report_string(url: &str, https_problem: Problem) -> Stri
|
|||
|
||||
let mut buf = String::new();
|
||||
let palette = DEFAULT_PALETTE;
|
||||
let report = to_https_problem_report(&alloc, url, https_problem);
|
||||
let report = to_https_problem_report(&alloc, url, https_problem, filename);
|
||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||
|
||||
buf
|
||||
|
@ -1126,6 +1130,7 @@ pub fn to_https_problem_report<'b>(
|
|||
alloc: &'b RocDocAllocator<'b>,
|
||||
url: &'b str,
|
||||
https_problem: Problem,
|
||||
filename: PathBuf,
|
||||
) -> Report<'b> {
|
||||
match https_problem {
|
||||
Problem::UnsupportedEncoding(not_supported_encoding) => {
|
||||
|
@ -1154,7 +1159,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "UNSUPPORTED ENCODING".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1189,7 +1194,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MULTIPLE ENCODINGS".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1224,7 +1229,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID CONTENT HASH".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1241,7 +1246,7 @@ pub fn to_https_problem_report<'b>(
|
|||
alloc.concat([alloc.tip(), alloc.reflow(r"Is the URL correct?")]),
|
||||
]);
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "NOTFOUND".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1268,7 +1273,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "IO ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1295,7 +1300,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "IO ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1324,7 +1329,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "HTTP ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1365,7 +1370,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID EXTENSION SUFFIX".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1398,7 +1403,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID EXTENSION".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1436,7 +1441,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID FRAGMENT".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1474,7 +1479,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MISSING PACKAGE HASH".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1500,7 +1505,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "HTTPS MANDATORY".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1543,7 +1548,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MISLEADING CHARACTERS".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1573,7 +1578,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE TOO LARGE".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1582,13 +1587,10 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_file_problem_report_string(filename: &Path, error: io::ErrorKind) -> String {
|
||||
pub fn to_file_problem_report_string(filename: PathBuf, error: io::ErrorKind) -> String {
|
||||
let src_lines: Vec<&str> = Vec::new();
|
||||
|
||||
let mut module_ids = ModuleIds::default();
|
||||
|
||||
let module_id = module_ids.get_or_insert(&"find module name somehow?".into());
|
||||
|
||||
let interns = Interns::default();
|
||||
|
||||
// Report parsing and canonicalization problems
|
||||
|
@ -1604,16 +1606,16 @@ pub fn to_file_problem_report_string(filename: &Path, error: io::ErrorKind) -> S
|
|||
|
||||
pub fn to_file_problem_report<'b>(
|
||||
alloc: &'b RocDocAllocator<'b>,
|
||||
filename: &Path,
|
||||
filename: PathBuf,
|
||||
error: io::ErrorKind,
|
||||
) -> Report<'b> {
|
||||
let filename: String = filename.to_str().unwrap().to_string();
|
||||
let filename_str: String = filename.to_str().unwrap().to_string();
|
||||
match error {
|
||||
io::ErrorKind::NotFound => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I am looking for this file, but it's not there:"),
|
||||
alloc
|
||||
.string(filename)
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::ParserSuggestion)
|
||||
.indent(4),
|
||||
alloc.concat([
|
||||
|
@ -1623,7 +1625,7 @@ pub fn to_file_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE NOT FOUND".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1633,7 +1635,7 @@ pub fn to_file_problem_report<'b>(
|
|||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I don't have the required permissions to read this file:"),
|
||||
alloc
|
||||
.string(filename)
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::ParserSuggestion)
|
||||
.indent(4),
|
||||
alloc
|
||||
|
@ -1641,7 +1643,7 @@ pub fn to_file_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE PERMISSION DENIED".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1652,13 +1654,16 @@ pub fn to_file_problem_report<'b>(
|
|||
let formatted = format!("{error}");
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I tried to read this file:"),
|
||||
alloc.string(filename).annotate(Annotation::Error).indent(4),
|
||||
alloc
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::Error)
|
||||
.indent(4),
|
||||
alloc.reflow(r"But ran into:"),
|
||||
alloc.text(formatted).annotate(Annotation::Error).indent(4),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE PROBLEM".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue