[SUPPORT]: Ignore ECInfoErr erros in GetSplitInfo #313

Merged
fyrchik merged 1 commit from aarifullin/frostfs-sdk-go:fix/ignore_ec_info_err into support/v1.0.0-rc.5 2024-12-12 07:12:50 +00:00

View file

@ -2985,11 +2985,12 @@ func (p *Pool) GetSplitInfo(ctx context.Context, cnrID cid.ID, objID oid.ID, tok
_, err := p.HeadObject(ctx, prm)
var errSplit *object.SplitInfoError
var errECInfo *object.ECInfoError
switch {
case errors.As(err, &errSplit):
return errSplit.SplitInfo(), nil
case err == nil:
case err == nil || errors.As(err, &errECInfo):
elebedeva marked this conversation as resolved
Review

Why using errors.As() here and not errors.Is()?

Why using `errors.As()` here and not `errors.Is()`?
Review

errors.Is checks exact error value (similar to == check) while errors.As tries to cast error to error type.

Exact value check is being used when error is explicitly defined (e.g. MyError := errors.New("my error").

returnedError := object.NewECInfoError(&object.ECInfo{
	Chunks: []v2object.ECChunk{{Index: 1, Total: 2}},
})

// Try to check error
var errECInfo *object.ECInfoError
fmt.Println(errors.Is(returnedError, errECInfo))  // false
fmt.Println(errors.As(returnedError, &errECInfo)) // true
`errors.Is` checks exact error value (similar to `==` check) while `errors.As` tries to cast error to error type. Exact value check is being used when error is explicitly defined (e.g. `MyError := errors.New("my error"`). ```go returnedError := object.NewECInfoError(&object.ECInfo{ Chunks: []v2object.ECChunk{{Index: 1, Total: 2}}, }) // Try to check error var errECInfo *object.ECInfoError fmt.Println(errors.Is(returnedError, errECInfo)) // false fmt.Println(errors.As(returnedError, &errECInfo)) // true ```
Review

@alexvanin is right.
errors.Is would have been used if var errECInfo = errors.New("object not found, ec info provided"), but it's introduced as complex type with data within

@alexvanin is right. `errors.Is` would have been used if `var errECInfo = errors.New("object not found, ec info provided")`, but it's introduced as complex type with data within
return nil, relations.ErrNoSplitInfo
default:
return nil, fmt.Errorf("failed to get raw object header: %w", err)