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: Error wrap may panic by nil error #179

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/avsregistry/avsregistry_chaincaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (ar *AvsRegistryServiceChainCaller) getOperatorPubkeys(ctx context.Context,
}
pubkeys, ok := ar.operatorPubkeysService.GetOperatorPubkeys(ctx, operatorAddr)
if !ok {
return types.OperatorPubkeys{}, types.WrapError(fmt.Errorf("Failed to get operator pubkeys from pubkey compendium service (operatorAddr: %v, operatorId: %v)", operatorAddr, operatorId), err)
return types.OperatorPubkeys{}, fmt.Errorf("Failed to get operator pubkeys from pubkey compendium service (operatorAddr: %v, operatorId: %v)", operatorAddr, operatorId)
}
return pubkeys, nil
}
13 changes: 13 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,18 @@ var (
)

func WrapError(mainErr error, subErr error) error {
// Some times the wrap will wrap a nil error
if mainErr == nil && subErr == nil {
return nil
}

if mainErr == nil && subErr != nil {
return fmt.Errorf("sub error: %s", subErr.Error())
}

if mainErr != nil && subErr == nil {
return fmt.Errorf("%s: unknown sub error", mainErr.Error())
}

return fmt.Errorf("%s: %s", mainErr.Error(), subErr.Error())
}
Loading