diff --git a/day-02/internal/one/solve.go b/day-02/internal/one/solve.go index e7cbbc9..08f9024 100644 --- a/day-02/internal/one/solve.go +++ b/day-02/internal/one/solve.go @@ -12,12 +12,15 @@ type comparator func([]int, int) bool func Solve(data []byte) (int, error) { r := bytes.NewReader(data) - sum := parseLines(r) + sum, err := parseLines(r) + if err != nil { + return 0, err + } return sum, nil } -func parseLines(r io.Reader) int { +func parseLines(r io.Reader) (int, error) { var sum int scanner := bufio.NewScanner(r) @@ -29,5 +32,9 @@ func parseLines(r io.Reader) int { } } - return sum + if err := scanner.Err(); err != nil { + return 0, err + } + + return sum, nil } diff --git a/day-02/internal/two/solve.go b/day-02/internal/two/solve.go index 0c6df9d..61dbdc6 100644 --- a/day-02/internal/two/solve.go +++ b/day-02/internal/two/solve.go @@ -13,12 +13,15 @@ type dampener func([]int, comparator, int) bool func Solve(data []byte) (int, error) { r := bytes.NewReader(data) - sum := parseLines(r) + sum, err := parseLines(r) + if err != nil { + return 0, err + } return sum, nil } -func parseLines(r io.Reader) int { +func parseLines(r io.Reader) (int, error) { var sum int scanner := bufio.NewScanner(r) @@ -30,7 +33,11 @@ func parseLines(r io.Reader) int { } } - return sum + if err := scanner.Err(); err != nil { + return 0, err + } + + return sum, nil } func check(fn dampener, nums []int, cmp comparator) bool {