Skip to content

Commit

Permalink
Merge pull request #79 from maxmind/greg/check-error
Browse files Browse the repository at this point in the history
Check Error() after Flush()
  • Loading branch information
horgh authored Aug 6, 2024
2 parents a8fb150 + 5696338 commit 05338a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
18 changes: 8 additions & 10 deletions convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,22 @@ func convert(
return fmt.Errorf("reading CSV: %w", err)
}

p, err := makePrefix(record[0])
prefix, err := netip.ParsePrefix(record[0])
if err != nil {
return err
return fmt.Errorf("parsing network (%s): %w", record[0], err)
}
err = writer.Write(makeLine(p, record[1:]))

err = writer.Write(makeLine(prefix, record[1:]))
if err != nil {
return fmt.Errorf("writing CSV: %w", err)
}
}

writer.Flush()
return nil
}

func makePrefix(network string) (netip.Prefix, error) {
prefix, err := netip.ParsePrefix(network)
if err != nil {
return prefix, fmt.Errorf("parsing network (%s): %w", network, err)
if err := writer.Error(); err != nil {
return fmt.Errorf("flushing CSV: %w", err)
}
return prefix, nil

return nil
}
3 changes: 2 additions & 1 deletion convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"net/netip"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -127,7 +128,7 @@ func checkLine(
network string,
expected []string,
) {
p, err := makePrefix(network)
p, err := netip.ParsePrefix(network)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 05338a8

Please sign in to comment.