fix(parser): return error in the case of empty file vector

This commit is contained in:
Orhun Parmaksız 2021-11-23 23:45:35 +03:00
parent e8c7890f98
commit 2379c6ddf3
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
2 changed files with 6 additions and 1 deletions

View file

@ -12,6 +12,9 @@ pub enum Error {
/// Error that may occur when the capture group does not exist.
#[error("capture group does not exist")]
CaptureError,
/// Error that may occur when the glob pattern returns zero results.
#[error("glob pattern has yielded no results")]
EmptyFileListError,
/// Error that may occur when a required file for parsing does not exist.
#[error("required file missing: '{0}'")]
MissingFileError(String),

View file

@ -45,6 +45,9 @@ impl<'a> Parser<'a> {
)?
.filter_map(StdResult::ok)
.collect::<Vec<DirEntry>>();
if glob_files.is_empty() {
return Err(Error::EmptyFileListError);
}
self.required_files.iter().try_for_each(|file_name| {
glob_files
.iter()
@ -53,7 +56,6 @@ impl<'a> Parser<'a> {
.ok_or_else(|| Error::MissingFileError(file_name.to_string()))
})?;
for file in glob_files {
println!("{:?}", file);
let input = reader::read_to_string(file.path())?;
let capture_group = self
.regex