Skip to content

Commit

Permalink
Check for storageReadOpenerErrorHook at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Feb 19, 2024
1 parent 519899f commit e8e8d0f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions engine/linksystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func (e *Engine) mkLinkSystem() ipld.LinkSystem {
lsys := cidlink.DefaultLinkSystem()

storageReadOpener := func(lctx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {

// If link corresponds to schema.NoEntries return error immediately.
if lnk == schema.NoEntries {
return nil, errNoEntries
Expand Down Expand Up @@ -152,13 +151,18 @@ func (e *Engine) mkLinkSystem() ipld.LinkSystem {
return bytes.NewBuffer(val), nil
}

lsys.StorageReadOpener = func(lctx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
r, err := storageReadOpener(lctx, lnk)
if err != nil && e.options.storageReadOpenerErrorHook != nil {
return r, e.options.storageReadOpenerErrorHook(lctx, lnk, err)
if e.options.storageReadOpenerErrorHook != nil {
lsys.StorageReadOpener = func(lctx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
r, err := storageReadOpener(lctx, lnk)
if err != nil {
return r, e.options.storageReadOpenerErrorHook(lctx, lnk, err)
}
return r, err
}
return r, err
} else {
lsys.StorageReadOpener = storageReadOpener
}

lsys.StorageWriteOpener = func(lctx ipld.LinkContext) (io.Writer, ipld.BlockWriteCommitter, error) {
buf := bytes.NewBuffer(nil)
return buf, func(lnk ipld.Link) error {
Expand Down

0 comments on commit e8e8d0f

Please sign in to comment.