container: clarify returned error

This commit is contained in:
Michael Muré
2025-01-13 13:25:57 +01:00
parent 10dd4fa6d1
commit 6d7fd28324

View File

@@ -2,7 +2,6 @@ package container
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"iter" "iter"
@@ -101,14 +100,12 @@ func (ctn Reader) GetToken(cid cid.Cid) (token.Token, error) {
} }
// GetDelegation is the same as GetToken but only return a delegation.Token, with the right type. // GetDelegation is the same as GetToken but only return a delegation.Token, with the right type.
// If not found, delegation.ErrDelegationNotFound is returned.
func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) { func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) {
tkn, err := ctn.GetToken(cid) tkn, err := ctn.GetToken(cid)
if errors.Is(err, ErrNotFound) { if err != nil { // only ErrNotFound expected
return nil, delegation.ErrDelegationNotFound return nil, delegation.ErrDelegationNotFound
} }
if err != nil {
return nil, err
}
if tkn, ok := tkn.(*delegation.Token); ok { if tkn, ok := tkn.(*delegation.Token); ok {
return tkn, nil return tkn, nil
} }