From e232a176d8bb0e2ccd510028d22a76f48eccf1c5 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 19:54:51 -0600 Subject: correctly categories not-found vs other errors in included files --- src/makefile/input.rs | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 912b119..e5473a1 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -2,7 +2,7 @@ use std::cell::Cell; use std::collections::HashMap; use std::error::Error as StdError; use std::fs::File; -use std::io::{BufRead, BufReader, Cursor, Error as IoError, Lines}; +use std::io::{BufRead, BufReader, Cursor, Error as IoError, ErrorKind as IoErrorKind, Lines}; use std::iter::Peekable; use std::path::Path; @@ -254,19 +254,28 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { let child_macros = self.macros.with_overlay(); let child = MakefileReader::read_file(self.args, child_macros, field) .with_context(|| format!("while including {}", field)); - if let Ok(child) = child { - let child = child.finish(); - self.extend(child); - } else { - if !original_line.starts_with('-') { - // TODO handle non-file-not-found errors - log::error!( - "{}:{}: included makefile {} not found", - &self.file_name, - line_number, - field - ); - self.failed_includes.push(field.to_owned()); + match child { + Ok(child) => { + let child = child.finish(); + self.extend(child); + } + Err(err) => { + if !original_line.starts_with('-') { + match err.downcast_ref::() { + Some(err) if err.kind() == IoErrorKind::NotFound => { + log::error!( + "{}:{}: included makefile {} not found", + &self.file_name, + line_number, + field, + ); + self.failed_includes.push(field.to_owned()); + } + _ => { + return Err(err); + } + } + } } } } -- cgit v1.2.3