fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Simplify error handling in readTOC (#825)

Small improvement to how we handle unknown or malformed sections when reading the TOC.

Note: this PR originally removed some of the "skip section" handling. That has been restored, since it is important for downgrades.

+17 -20
+17 -20
read.go
··· 125 125 if err != nil { 126 126 return err 127 127 } 128 + 128 129 sec := secs[tag] 129 - if sec != nil && sec.kind() == sectionKind(kind) { 130 - // happy path 131 - if err := sec.read(r); err != nil { 132 - return err 130 + if sec == nil || sec.kind() != sectionKind(kind) { 131 + // If we don't recognize the section, we may be reading a newer index than the current version. Use 132 + // a "dummy section" struct to skip over it. 133 + log.Printf("encountered unrecognized index section (%s), skipping over it", tag) 134 + switch sectionKind(kind) { 135 + case sectionKindSimple: 136 + sec = &simpleSection{} 137 + case sectionKindCompound: 138 + sec = &lazyCompoundSection{} 139 + case sectionKindCompoundLazy: 140 + sec = &lazyCompoundSection{} 141 + default: 142 + return fmt.Errorf("unknown section kind %d", kind) 133 143 } 134 - continue 135 144 } 136 - // error case: skip over unknown section 137 - if sec == nil { 138 - log.Printf("file %s TOC has unknown section %q", r.r.Name(), tag) 139 - } else { 140 - return fmt.Errorf("file %s TOC section %q expects kind %d, got kind %d", r.r.Name(), tag, 141 - kind, sec.kind()) 142 - } 143 - if kind == 0 { 144 - if err := (&simpleSection{}).read(r); err != nil { 145 - return err 146 - } 147 - } else if kind == 1 { 148 - if err := (&compoundSection{}).read(r); err != nil { 149 - return err 150 - } 145 + 146 + if err := sec.read(r); err != nil { 147 + return err 151 148 } 152 149 } 153 150 } else {