Skip to content

Commit

Permalink
util: Removing JoinError in favor of fmt.Errorf
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Perez <thingee@gmail.com>
  • Loading branch information
Thingee authored and mergify[bot] committed May 22, 2024
1 parent 8f7a4c4 commit c8af2b6
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 111 deletions.
6 changes: 3 additions & 3 deletions internal/cephfs/core/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *subVolumeClient) GetVolumeRootPathCeph(ctx context.Context) (string, er
if err != nil {
log.ErrorLog(ctx, "failed to get the rootpath for the vol %s: %s", s.VolID, err)
if errors.Is(err, rados.ErrNotFound) {
return "", util.JoinErrors(cerrors.ErrVolumeNotFound, err)
return "", fmt.Errorf("Failed as %w (internal %w)", cerrors.ErrVolumeNotFound, err)
}

return "", err
Expand Down Expand Up @@ -303,10 +303,10 @@ func (s *subVolumeClient) PurgeVolume(ctx context.Context, force bool) error {
if err != nil {
log.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", s.VolID, s.FsName, err)
if strings.Contains(err.Error(), cerrors.VolumeNotEmpty) {
return util.JoinErrors(cerrors.ErrVolumeHasSnapshots, err)
return fmt.Errorf("Failed as %w (internal %w)", cerrors.ErrVolumeHasSnapshots, err)
}
if errors.Is(err, rados.ErrNotFound) {
return util.JoinErrors(cerrors.ErrVolumeNotFound, err)
return fmt.Errorf("Failed as %w (internal %w)", cerrors.ErrVolumeNotFound, err)
}

return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cephfs/store/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func NewVolumeOptionsFromVolID(
if err != nil {
err = fmt.Errorf("error decoding volume ID (%s): %w", volID, err)

return nil, nil, util.JoinErrors(cerrors.ErrInvalidVolID, err)
return nil, nil, fmt.Errorf("Failed as %w (internal %w)", cerrors.ErrInvalidVolID, err)
}
volOptions.ClusterID = vi.ClusterID
vid.VolumeID = volID
Expand Down
2 changes: 1 addition & 1 deletion internal/journal/omap.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func setOMapKeys(

func omapPoolError(err error) error {
if errors.Is(err, rados.ErrNotFound) {
return util.JoinErrors(util.ErrPoolNotFound, err)
return fmt.Errorf("Failed as %w (internal %w)", util.ErrPoolNotFound, err)
}

return err
Expand Down
8 changes: 4 additions & 4 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (ri *rbdImage) open() (*librbd.Image, error) {
image, err := librbd.OpenImage(ri.ioctx, ri.RbdImageName, librbd.NoSnapshot)
if err != nil {
if errors.Is(err, librbd.ErrNotFound) {
err = util.JoinErrors(ErrImageNotFound, err)
err = fmt.Errorf("Failed as %w (internal %w)", ErrImageNotFound, err)
}

return nil, err
Expand Down Expand Up @@ -896,7 +896,7 @@ func (ri *rbdImage) flatten() error {
// rbd image flatten will fail if the rbd image does not have a parent
parent, pErr := ri.getParentName()
if pErr != nil {
return util.JoinErrors(err, pErr)
return fmt.Errorf("Failed as %w (internal %w)", err, pErr)
}
if parent == "" {
return nil
Expand Down Expand Up @@ -1448,7 +1448,7 @@ func (ri *rbdImage) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) erro
}
err = snap.Remove()
if errors.Is(err, librbd.ErrNotFound) {
return util.JoinErrors(ErrSnapNotFound, err)
return fmt.Errorf("Failed as %w (internal %w)", ErrSnapNotFound, err)
}

return err
Expand Down Expand Up @@ -1779,7 +1779,7 @@ func lookupRBDImageMetadataStash(metaDataPath string) (rbdImageMetadataStash, er
return imgMeta, fmt.Errorf("failed to read stashed JSON image metadata from path (%s): %w", fPath, err)
}

return imgMeta, util.JoinErrors(ErrMissingStash, err)
return imgMeta, fmt.Errorf("Failed as %w (internal %w)", ErrMissingStash, err)
}

err = json.Unmarshal(encodedBytes, &imgMeta)
Expand Down
8 changes: 4 additions & 4 deletions internal/util/cephcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam
ioctx, err := conn.GetIoctx(poolName)
if err != nil {
if errors.Is(err, ErrPoolNotFound) {
err = JoinErrors(ErrObjectNotFound, err)
err = fmt.Errorf("Failed as %w (internal %w)", ErrObjectNotFound, err)
}

return err
Expand All @@ -248,7 +248,7 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam

err = ioctx.Create(objectName, rados.CreateExclusive)
if errors.Is(err, rados.ErrObjectExists) {
return JoinErrors(ErrObjectExists, err)
return fmt.Errorf("Failed as %w (internal %w)", ErrObjectExists, err)
} else if err != nil {
log.ErrorLog(ctx, "failed creating omap (%s) in pool (%s): (%v)", objectName, poolName, err)

Expand All @@ -271,7 +271,7 @@ func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolNam
ioctx, err := conn.GetIoctx(poolName)
if err != nil {
if errors.Is(err, ErrPoolNotFound) {
err = JoinErrors(ErrObjectNotFound, err)
err = fmt.Errorf("Failed as %w (internal %w)", ErrObjectNotFound, err)
}

return err
Expand All @@ -284,7 +284,7 @@ func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolNam

err = ioctx.Delete(oMapName)
if errors.Is(err, rados.ErrNotFound) {
return JoinErrors(ErrObjectNotFound, err)
return fmt.Errorf("Failed as %w (internal %w)", ErrObjectNotFound, err)
} else if err != nil {
log.ErrorLog(ctx, "failed removing omap (%s) in pool (%s): (%v)", oMapName, poolName, err)

Expand Down
2 changes: 1 addition & 1 deletion internal/util/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (cc *ClusterConnection) GetIoctx(pool string) (*rados.IOContext, error) {
if err != nil {
// ErrNotFound indicates the Pool was not found
if errors.Is(err, rados.ErrNotFound) {
err = JoinErrors(ErrPoolNotFound, err)
err = fmt.Errorf("Failed as %w (internal %w)", ErrPoolNotFound, err)
} else {
err = fmt.Errorf("failed to open IOContext for pool %s: %w", pool, err)
}
Expand Down
26 changes: 0 additions & 26 deletions internal/util/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package util

import (
"errors"
"fmt"
)

var (
Expand All @@ -38,28 +37,3 @@ var (
// ErrMissingConfigForMonitor is returned when clusterID is not found for the mon.
ErrMissingConfigForMonitor = errors.New("missing configuration of cluster ID for monitor")
)

type pairError struct {
first error
second error
}

func (e pairError) Error() string {
return fmt.Sprintf("%v: %v", e.first, e.second)
}

// Is checks if target error is wrapped in the first error.
func (e pairError) Is(target error) bool {
return errors.Is(e.first, target)
}

// Unwrap returns the second error.
func (e pairError) Unwrap() error {
return e.second
}

// JoinErrors combines two errors. Of the returned error, Is() follows the first
// branch, Unwrap() follows the second branch.
func JoinErrors(e1, e2 error) error {
return pairError{e1, e2}
}
71 changes: 0 additions & 71 deletions internal/util/errors_test.go

This file was deleted.

0 comments on commit c8af2b6

Please sign in to comment.