Skip to content

Commit 04bcbda

Browse files
authored
CLI: fix invalid filenames not printing an error (#235)
1 parent a1c7ea6 commit 04bcbda

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ fn main() {
2929
let compile_parameters: Result<CompileParameters, ParameterError> =
3030
CompileParameters::parse(args);
3131
match compile_parameters {
32-
Ok(cp) => main_compile(cp),
32+
Ok(cp) => {
33+
if let Err(msg) = main_compile(cp) {
34+
println!("Error: {}", msg);
35+
std::process::exit(1);
36+
}
37+
}
3338
Err(err) => err.exit(), // prints the nice message to std-out
3439
}
3540
}
@@ -40,18 +45,23 @@ fn create_file_paths(inputs: &[String]) -> Result<Vec<FilePath>, String> {
4045
let paths =
4146
glob(input).map_err(|e| format!("Failed to read glob pattern: {}, ({})", input, e))?;
4247

48+
let source_count_before = sources.len();
4349
for p in paths {
4450
let path = p.map_err(|err| format!("Illegal path: {:}", err))?;
4551
sources.push(FilePath {
4652
path: path.to_string_lossy().to_string(),
4753
});
4854
}
55+
56+
if sources.len() <= source_count_before {
57+
return Err(format!("No such file(s): {}", input));
58+
}
4959
}
5060
Ok(sources)
5161
}
5262

53-
fn main_compile(parameters: CompileParameters) {
54-
let sources = create_file_paths(&parameters.input).unwrap();
63+
fn main_compile(parameters: CompileParameters) -> Result<(), String> {
64+
let sources = create_file_paths(&parameters.input)?;
5565

5666
let output_filename = parameters.output_name().unwrap();
5767
let encoding = parameters.encoding;
@@ -82,4 +92,5 @@ fn main_compile(parameters: CompileParameters) {
8292
compile_to_ir(sources, encoding, &output_filename).unwrap();
8393
}
8494
}
95+
Ok(())
8596
}

0 commit comments

Comments
 (0)