Stop asinfo-gen when the as.csv download breaks off (closes #177)
check / check (push) Waiting to run

parseCSV skipped a record on any read error and asked for the next one.
When the download of as.csv broke off, the response body returned the
same error on every read, so the generator logged it forever and make
asupdate never finished.

parseCSV now skips only a record that does not parse, a csv.ParseError.
Any other read error ends it with that error, so the generator exits
non-zero and script/asupdate keeps the old list.

Model: opus-5-5
This commit is contained in:
2026-10-27 02:00:27 +00:00
parent 023c3f9b41
commit 772a5c6ba3
3 changed files with 81 additions and 2 deletions
+9 -2
View File
@@ -85,7 +85,8 @@ func main() {
// parseCSV reads as.csv from r and returns its ASes, with the handle and the
// description as the file spells them. A header whose first columns are not
// the AS number, the handle and the description is an error. A record that
// does not parse is logged and skipped. A file left with no AS is an error.
// does not parse is logged and skipped. A read that fails, such as on a broken
// download, is an error. A file left with no AS is an error.
func parseCSV(r io.Reader) ([]ASInfo, error) {
reader := csv.NewReader(r)
@@ -109,12 +110,18 @@ func parseCSV(r io.Reader) ([]ASInfo, error) {
break
}
if err != nil {
if _, ok := errors.AsType[*csv.ParseError](err); ok {
log.Printf("Error reading CSV record: %v", err)
continue
}
// Any other error comes from the download, such as a broken
// connection. Every later read returns it again.
if err != nil {
return nil, fmt.Errorf("read CSV record: %w", err)
}
asn, err := strconv.Atoi(record[0])
if err != nil {
log.Printf("Invalid ASN %q: %v", record[0], err)