diff --git a/convert/convert.go b/convert/convert.go index a83a225..8893a92 100644 --- a/convert/convert.go +++ b/convert/convert.go @@ -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 } diff --git a/convert/convert_test.go b/convert/convert_test.go index b8c0522..08368c7 100644 --- a/convert/convert_test.go +++ b/convert/convert_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "net/netip" "os" "strings" "testing" @@ -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) }