Skip to content

Commit

Permalink
feat(parsing): give serviceable parsing error details to users (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTMjugador authored Jan 14, 2025
1 parent 8667ec3 commit ba64b92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum ErrorKind {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
ErrorKind::Expression(ref expr) => write!(f, "Invalid expression: {}", expr),
ErrorKind::Expression(ref expr) => write!(f, "{expr}"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl TryFrom<Cow<'_, str>> for Schedule {

fn try_from(expression: Cow<'_, str>) -> Result<Self, Self::Error> {
match schedule.parse(&expression) {
Ok(schedule_fields) => Ok(Schedule::new(expression.into_owned(), schedule_fields)), // Extract from nom tuple
Err(_) => Err(ErrorKind::Expression("Invalid cron expression.".to_owned()).into()), //TODO: Details
Ok(schedule_fields) => Ok(Schedule::new(expression.into_owned(), schedule_fields)), // Extract from winnow tuple
Err(parse_error) => Err(ErrorKind::Expression(format!("{parse_error}")).into()),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ mod test {
&[Token::String(
"definitively an invalid value for a cron schedule!",
)],
"Invalid expression: Invalid cron expression.",
"definitively an invalid value for a cron schedule!\n\
^\n\
The 'Seconds' field does not support using names. 'definitively' specified.",
);
}

Expand Down

0 comments on commit ba64b92

Please sign in to comment.