Skip to content

Commit dedf056

Browse files
committed
remove unwrap
1 parent 94fd369 commit dedf056

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/compiler.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ impl Compiler {
8484
require_literal_separator: false,
8585
require_literal_leading_dot: false,
8686
};
87-
let import_paths = glob::glob_with(&import_base_str, glob_options).unwrap();
87+
let import_paths = glob::glob_with(&import_base_str, glob_options)
88+
.map_err(|error| Error::ImportGlob { error, path: *path })?;
8889
for import in import_paths {
89-
let import = import.unwrap();
90+
let Ok(import) = import else { continue };
9091

9192
if import.is_file() {
9293
if current.file_path.contains(&import) {
@@ -354,6 +355,22 @@ x:
354355
);
355356
}
356357

358+
#[test]
359+
fn invalid_glob_imports() {
360+
let justfile = r#"
361+
import "./subdir/***.just"
362+
"#;
363+
let tmp = temptree! {
364+
justfile: justfile,
365+
};
366+
let loader = Loader::new();
367+
let justfile_path = tmp.path().join("justfile");
368+
let error = Compiler::compile(&loader, &justfile_path).unwrap_err();
369+
let expected = "error: import path glob: Pattern syntax error";
370+
let actual = error.color_display(Color::never()).to_string();
371+
assert!(actual.contains(expected), "Actual: {actual}");
372+
}
373+
357374
#[test]
358375
fn find_module_file() {
359376
#[track_caller]

src/error.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ pub(crate) enum Error<'src> {
107107
io_error: io::Error,
108108
},
109109
Homedir,
110+
ImportGlob {
111+
error: glob::PatternError,
112+
path: Token<'src>,
113+
},
110114
InitExists {
111115
justfile: PathBuf,
112116
},
@@ -209,7 +213,7 @@ impl<'src> Error<'src> {
209213
Self::Backtick { token, .. } => Some(*token),
210214
Self::Compile { compile_error } => Some(compile_error.context()),
211215
Self::FunctionCall { function, .. } => Some(function.token),
212-
Self::MissingImportFile { path } => Some(*path),
216+
Self::MissingImportFile { path } | Self::ImportGlob { path, .. } => Some(*path),
213217
_ => None,
214218
}
215219
}
@@ -389,6 +393,7 @@ impl<'src> ColorDisplay for Error<'src> {
389393
Homedir => {
390394
write!(f, "Failed to get homedir")?;
391395
}
396+
ImportGlob { error, .. } => write!(f, "import path glob: {error}")?,
392397
InitExists { justfile } => {
393398
write!(f, "Justfile `{}` already exists", justfile.display())?;
394399
}

0 commit comments

Comments
 (0)