Skip to content

Commit

Permalink
chore: document non-reachable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc committed Nov 2, 2024
1 parent 75c98da commit dd48160
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/utils/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ func ParseDuration(s string) (time.Duration, error) {
strings.ReplaceAll(s, " ", ""), -1,
)
if matches == nil {
// The `reDurationString` regex should ensure that there is at least
// one match, so this should never happen.
return 0, fmt.Errorf("invalid duration: %s", s)
}

totalDuration := time.Duration(0)
for _, match := range matches {
duration, err := strconv.ParseInt(match[1], 10, 64)
if err != nil {
// The duration string was already validated above, and `match[1]`
// should always be a valid number.
return 0, fmt.Errorf("invalid duration: %w", err)
}

Expand Down

0 comments on commit dd48160

Please sign in to comment.