ppErrorPreprocess Make use of the existing Error::Preprocess
Before this commit, inputs with invalid pp syntax are reported using `Error::Parse` which is also used to report invalid post-pp syntax. In svlint/svls, `Error::Parse` is reported to the user as "parse error" without specifying if that's pre or post pp. This commit makes it possible for future versions of svlint/svls to report "preprocess error", thus helping users to identify pp issues. - `Error::Preprocess` appears to be defined but unused. - Add the argument `Option<(PathBuf, usize)>` to `Error::Preprocess`, same as `Error::Parse`. - Update `preprocess_str()` to use `Error::Preprocess` in all 5 instances.
This commit is contained in:
parent
6c28a6157d
commit
f9e93d18bd
@ -7,29 +7,38 @@ use thiserror::Error;
|
|||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("IO error: {0}")]
|
#[error("IO error: {0}")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
|
|
||||||
#[error("File error: {path:?}")]
|
#[error("File error: {path:?}")]
|
||||||
File {
|
File {
|
||||||
#[source]
|
#[source]
|
||||||
source: std::io::Error,
|
source: std::io::Error,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Include error")]
|
#[error("Include error")]
|
||||||
Include {
|
Include {
|
||||||
#[from]
|
#[from]
|
||||||
source: Box<Error>,
|
source: Box<Error>,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("Parse error: {0:?}")]
|
#[error("Parse error: {0:?}")]
|
||||||
Parse(Option<(PathBuf, usize)>),
|
Parse(Option<(PathBuf, usize)>),
|
||||||
#[error("Preprocess error")]
|
|
||||||
Preprocess,
|
#[error("Preprocess error: {0:?}")]
|
||||||
|
Preprocess(Option<(PathBuf, usize)>),
|
||||||
|
|
||||||
#[error("Define argument not found: {0}")]
|
#[error("Define argument not found: {0}")]
|
||||||
DefineArgNotFound(String),
|
DefineArgNotFound(String),
|
||||||
|
|
||||||
#[error("Define not found: {0}")]
|
#[error("Define not found: {0}")]
|
||||||
DefineNotFound(String),
|
DefineNotFound(String),
|
||||||
|
|
||||||
#[error("Define must have argument")]
|
#[error("Define must have argument")]
|
||||||
DefineNoArgs,
|
DefineNoArgs,
|
||||||
|
|
||||||
#[error("Exceed recursive limit")]
|
#[error("Exceed recursive limit")]
|
||||||
ExceedRecursiveLimit,
|
ExceedRecursiveLimit,
|
||||||
|
|
||||||
#[error("Include line can't have other items")]
|
#[error("Include line can't have other items")]
|
||||||
IncludeLine,
|
IncludeLine,
|
||||||
}
|
}
|
||||||
|
@ -226,19 +226,19 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
|
|
||||||
let span = Span::new_extra(&s, SpanInfo::default());
|
let span = Span::new_extra(&s, SpanInfo::default());
|
||||||
let (_, pp_text) = all_consuming(pp_parser)(span).map_err(|x| match x {
|
let (_, pp_text) = all_consuming(pp_parser)(span).map_err(|x| match x {
|
||||||
nom::Err::Incomplete(_) => Error::Parse(None),
|
nom::Err::Incomplete(_) => Error::Preprocess(None),
|
||||||
nom::Err::Error(e) => {
|
nom::Err::Error(e) => {
|
||||||
if let Some(pos) = error_position(&e) {
|
if let Some(pos) = error_position(&e) {
|
||||||
Error::Parse(Some((PathBuf::from(path.as_ref()), pos)))
|
Error::Preprocess(Some((PathBuf::from(path.as_ref()), pos)))
|
||||||
} else {
|
} else {
|
||||||
Error::Parse(None)
|
Error::Preprocess(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nom::Err::Failure(e) => {
|
nom::Err::Failure(e) => {
|
||||||
if let Some(pos) = error_position(&e) {
|
if let Some(pos) = error_position(&e) {
|
||||||
Error::Parse(Some((PathBuf::from(path.as_ref()), pos)))
|
Error::Preprocess(Some((PathBuf::from(path.as_ref()), pos)))
|
||||||
} else {
|
} else {
|
||||||
Error::Parse(None)
|
Error::Preprocess(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user