Skip to content

Commit

Permalink
Simplify error handling in readTOC
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Sep 13, 2024
1 parent 44eab0c commit 8166b34
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"fmt"
"hash/crc64"
"log"
"os"
"sort"

Expand Down Expand Up @@ -126,28 +125,12 @@ func (r *reader) readTOC(toc *indexTOC) error {
return err
}
sec := secs[tag]
if sec != nil && sec.kind() == sectionKind(kind) {
// happy path
if err := sec.read(r); err != nil {
return err
}
continue
if sec == nil || sec.kind() != sectionKind(kind) {
return fmt.Errorf("encountered malformed undex section. tag: %s, kind: %d", tag, sectionKind(kind))
}
// error case: skip over unknown section
if sec == nil {
log.Printf("file %s TOC has unknown section %q", r.r.Name(), tag)
} else {
return fmt.Errorf("file %s TOC section %q expects kind %d, got kind %d", r.r.Name(), tag,
kind, sec.kind())
}
if kind == 0 {
if err := (&simpleSection{}).read(r); err != nil {
return err
}
} else if kind == 1 {
if err := (&compoundSection{}).read(r); err != nil {
return err
}

if err := sec.read(r); err != nil {
return err
}
}
} else {
Expand Down

0 comments on commit 8166b34

Please sign in to comment.