Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panicks with invalid unwrap() when passed a date out of range #1

Closed
mirrorwitch opened this issue Oct 2, 2023 · 1 comment
Closed

Comments

@mirrorwitch
Copy link

Here's a test case:

use human_date_parser::{from_human_time, ParseResult};

fn main() {
    let date = from_human_time("2023-11-31");
    let foo = match date {
        Ok(ParseResult::DateTime(_)) => 1,
        Ok(ParseResult::Date(_)) => 2,
        Ok(ParseResult::Time(_)) => 3,
        Err(_) => 4,
    };
	println!("{foo}");
}

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseError(OutOfRange)',
/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f
/human-date-parser-0.1.1/src/lib.rs:186:64

Here's the section on lib.rs:

           Rule::IsoDate => {
              let from_str = NaiveDate::from_str(first.as_str()).unwrap(); => NaiveDate
              Ok(from_str)
          }
technologicalMayhem added a commit that referenced this issue Apr 4, 2024
Fixes #gh-1
Fixes the issue by gracefully failing with an error value on an invalid date, instead of panicking
@technologicalMayhem
Copy link
Owner

Sorry for only getting around to fixing this now. But this should now return a error value instead of panicking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants