diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index bd115cd16a..6d4e38495b 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -3841,8 +3841,7 @@ struct HeaderOutput<'a> { fn ensure_roc_file<'a>(filename: &PathBuf, src_bytes: &[u8]) -> Result<(), LoadingProblem<'a>> { match filename.extension() { Some(ext) => { - let roc_ext = std::ffi::OsStr::new("roc"); - if roc_ext != ext { + if ext != ROC_FILE_EXTENSION { return Err(LoadingProblem::FileProblem { filename: filename.clone(), error: io::ErrorKind::Unsupported, diff --git a/crates/compiler/load_internal/tests/test_load.rs b/crates/compiler/load_internal/tests/test_load.rs index d5716c1d04..b4a2bce918 100644 --- a/crates/compiler/load_internal/tests/test_load.rs +++ b/crates/compiler/load_internal/tests/test_load.rs @@ -1213,10 +1213,10 @@ fn non_roc_file_extension() { let expected = indoc!( r" - ── EXPECTED ROC FILE in tmp/non_roc_file_extension/main.md ───────────────────── + ── NOT A ROC FILE in tmp/non_roc_file_extension/main.md ──────────────────────── - I am expecting a roc application file with either `.roc` or no - extension. Instead I found a file with extension `.md`" + I expected a file with extension `.roc` or without extension. + Instead I received a file with extension `.md`." ); let color_start = String::from_utf8(vec![27, 91, 51, 54, 109]).unwrap(); let color_end = String::from_utf8(vec![27, 91, 48, 109]).unwrap(); @@ -1245,13 +1245,15 @@ fn roc_file_no_extension() { let expected = indoc!( r" - ── EXPECTED ROC FILE in tmp/roc_file_no_extension/main ───────────────────────── + ── NOT A ROC FILE in tmp/roc_file_no_extension/main ──────────────────────────── - I am expecting a roc application file with either `.roc` or no - extension and a shebang directive. Instead I found a file without an - extension and without a shebang + I expected a file with either: + - extension `.roc` + - no extension and a roc shebang as the first line, e.g. + `#!/home/username/bin/roc_nightly/roc` - Consider starting the file with `#!` and the path to your roc binarya" + The provided file did not start with a shebang `#!` containing the + string `roc`. Is tmp/roc_file_no_extension/main a Roc file?" ); let color_start = String::from_utf8(vec![27, 91, 51, 54, 109]).unwrap(); let color_end = String::from_utf8(vec![27, 91, 48, 109]).unwrap(); diff --git a/crates/reporting/src/report.rs b/crates/reporting/src/report.rs index d3b9a7be9c..b5f242ddf0 100644 --- a/crates/reporting/src/report.rs +++ b/crates/reporting/src/report.rs @@ -1654,22 +1654,25 @@ pub fn to_file_problem_report<'b>( } io::ErrorKind::Unsupported => { let doc = match filename.extension() { - Some(ext) => { - alloc.concat(vec![ - alloc.reflow( - r"I am expecting a roc application file with either `.roc` or no extension. Instead I found a file with extension `.", - ), - alloc.as_string(ext.to_string_lossy()), - alloc.as_string("`"), - ]) - } + Some(ext) => alloc.concat(vec![ + alloc.reflow(r"I expected a file with extension `.roc` or without extension."), + alloc.hardline(), + alloc.reflow(r"Instead I received a file with extension `."), + alloc.as_string(ext.to_string_lossy()), + alloc.as_string("`."), + ]), None => { alloc.stack(vec![ - alloc.concat(vec![ - alloc.reflow(r"I am expecting a roc application file with either `.roc` or no extension and a shebang directive. "), - alloc.reflow(r"Instead I found a file without an extension and without a shebang"), + alloc.vcat(vec![ + alloc.reflow(r"I expected a file with either:"), + alloc.reflow("- extension `.roc`"), + alloc.reflow("- no extension and a roc shebang as the first line, e.g. `#!/home/username/bin/roc_nightly/roc`"), ]), - alloc.reflow(r"Consider starting the file with `#!` and the path to your roc binary"), + alloc.concat(vec![ + alloc.reflow("The provided file did not start with a shebang `#!` containing the string `roc`. Is "), + alloc.as_string(filename.to_string_lossy()), + alloc.reflow(" a Roc file?"), + ]) ]) } }; @@ -1677,7 +1680,7 @@ pub fn to_file_problem_report<'b>( Report { filename, doc, - title: "EXPECTED ROC FILE".to_string(), + title: "NOT A ROC FILE".to_string(), severity: Severity::Fatal, } }