TryBugHunt
rustNull / UndefinedHard

Time without minutes is accepted as a full hour

BugFind the bug and fix the code

What it should do

parse_minutes(time) turns a time written as "HH:MM" into minutes after midnight. Anything that is not a valid HH:MM time returns None. Example: parse_minutes("09:30") → Some(570)

What happens instead

parse_minutes("12") returns Some(720) instead of None.

fn parse_minutes(time: &str) -> Option<i32> {
    let mut parts = time.split(':');
    let hours = parts.next()?.trim().parse::<i32>().ok()?;
    let minutes = parts.next().unwrap_or("0").trim().parse::<i32>().ok()?;
    if parts.next().is_some() || hours > 23 || minutes > 59 {
        return None;
    }
    Some(hours * 60 + minutes)
}

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the null and undefined errors pattern

An Option or Result unwrapped as if it always held a value.

What you'll practise

A hard Rust debugging exercise about null and undefined errors: an Option or Result unwrapped as if it always held a value.

The checks your fix must pass

Signs of this kind of bug

Spoiler: why this bug happens(try it first; the hints get warmer one at a time)

What went wrong: When the text has no colon, the second parts.next() is None, which means the minutes are missing and the time is invalid. unwrap_or("0") replaces that None with "0", so "12" is quietly accepted as 12:00. The missing value is hidden instead of reported.

The fix: Use ? like the hours line does: parts.next()?. A missing minutes part now makes the whole function return None.

Remember: a default is only right when the value is truly optional. If a missing piece makes the input invalid, pass the None on with ? or a match, and test input with a part left out.

The pattern behind it: null and undefined errors.

More null and undefined errors to practise

Related errors

Embed this challenge on your site

Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.

<iframe src="https://trybughunt.com/embed/0a07e67d-dc08-4499-a631-26bb10ce1092" title="Debugging challenge: Time without minutes is accepted as a full hour" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/0a07e67d-dc08-4499-a631-26bb10ce1092">TryBugHunt</a></p>