Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): replace unrecoverable panic with error #1951

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the named return variable?

// 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