Skip to content

Schedule: Fix panic on duration conversion with proper error handling #29

Description

@PedramNavid

Problem

Using .unwrap() will panic if the duration is too large to convert (> ~584 years).

Locations: src/core/schedule.rs:204 and src/core/schedule.rs:237

let next = after + chrono::Duration::from_std(*duration).unwrap();

Recommendation

Return an error instead:

let chrono_duration = chrono::Duration::from_std(*duration)
    .map_err(|_| ScheduleError::InvalidInterval("duration too large".into()))?;
let next = after + chrono_duration;

Apply this fix in both next_after() (line 204) and next_n_after() (line 237).

Priority

Critical - Panics should be avoided in library code.


Created from PR review: #28 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions