updated error messages

This commit is contained in:
Trevor Settles 2024-02-08 15:25:15 -07:00
parent 4b4ad47312
commit 5f6d259e5d
No known key found for this signature in database
GPG key ID: F46B83058222DBAA
3 changed files with 28 additions and 24 deletions

View file

@ -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,

View file

@ -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();

View file

@ -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,
}
}