Skip to content

Commit

Permalink
fix(table): Replace unrecoverable panic with error
Browse files Browse the repository at this point in the history
  • Loading branch information
andresa0425 authored and AveralS committed May 17, 2023
1 parent ef0e552 commit 4d25614
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ func OpenInMemoryTable(data []byte, id uint64, opt *Options) (*Table, error) {
return t, nil
}

func (t *Table) initBiggestAndSmallest() error {
func (t *Table) initBiggestAndSmallest() (err error) {
// This defer will help gathering debugging info incase initIndex crashes.
defer func() {
if r := recover(); r != nil {
// Use defer for printing info because there may be an intermediate panic.
var debugBuf bytes.Buffer
defer func() {
panic(fmt.Sprintf("%s\n== Recovered ==\n", debugBuf.String()))
err = fmt.Errorf("recovered: %s", r)
}()

// Get the count of null bytes at the end of file. This is to make sure if there was an
Expand Down Expand Up @@ -398,7 +398,6 @@ func (t *Table) initBiggestAndSmallest() error {
}
}()

var err error
var ko *fb.BlockOffset
if ko, err = t.initIndex(); err != nil {
return y.Wrapf(err, "failed to read index.")
Expand All @@ -413,7 +412,7 @@ func (t *Table) initBiggestAndSmallest() error {
return y.Wrapf(it2.err, "failed to initialize biggest for table %s", t.Filename())
}
t.biggest = y.Copy(it2.Key())
return nil
return err
}

func (t *Table) read(off, sz int) ([]byte, error) {
Expand Down

0 comments on commit 4d25614

Please sign in to comment.