Remove error package and cause functions (#5784)

master
kannappanr 7 years ago committed by GitHub
parent 217fb470a7
commit cef992a395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/api-errors.go
  2. 4
      cmd/bucket-handlers.go
  3. 3
      cmd/bucket-notification-handlers.go
  4. 2
      cmd/bucket-policy-handlers.go
  5. 14
      cmd/bucket-policy.go
  6. 3
      cmd/disk-cache-fs.go
  7. 13
      cmd/disk-cache.go
  8. 9
      cmd/format-xl.go
  9. 4
      cmd/format-xl_test.go
  10. 3
      cmd/fs-v1-helpers.go
  11. 37
      cmd/fs-v1-helpers_test.go
  12. 11
      cmd/fs-v1-multipart.go
  13. 11
      cmd/fs-v1-multipart_test.go
  14. 12
      cmd/fs-v1.go
  15. 38
      cmd/fs-v1_test.go
  16. 3
      cmd/gateway/azure/gateway-azure.go
  17. 3
      cmd/gateway/azure/gateway-azure_test.go
  18. 7
      cmd/gateway/oss/gateway-oss_test.go
  19. 9
      cmd/gateway/s3/gateway-s3_test.go
  20. 4
      cmd/handler-utils_test.go
  21. 18
      cmd/lock-instrument_test.go
  22. 9
      cmd/notification.go
  23. 14
      cmd/object-api-errors.go
  24. 3
      cmd/object-api-input-checks.go
  25. 4
      cmd/object-api-multipart_test.go
  26. 4
      cmd/object-api-putobject_test.go
  27. 2
      cmd/object-handlers.go
  28. 8
      cmd/object_api_suite_test.go
  29. 12
      cmd/os-reliable_test.go
  30. 3
      cmd/prepare-storage.go
  31. 6
      cmd/storage-rpc-server_test.go
  32. 15
      cmd/utils.go
  33. 24
      cmd/utils_test.go
  34. 8
      cmd/web-handlers.go
  35. 7
      cmd/xl-sets.go
  36. 11
      cmd/xl-v1-bucket.go
  37. 3
      cmd/xl-v1-common.go
  38. 21
      cmd/xl-v1-healing.go
  39. 5
      cmd/xl-v1-healing_test.go
  40. 6
      cmd/xl-v1-list-objects.go
  41. 9
      cmd/xl-v1-metadata.go
  42. 8
      cmd/xl-v1-metadata_test.go
  43. 11
      cmd/xl-v1-multipart.go
  44. 3
      cmd/xl-v1-multipart_test.go
  45. 5
      cmd/xl-v1-object.go
  46. 5
      cmd/xl-v1-object_test.go
  47. 3
      cmd/xl-v1-utils.go
  48. 9
      cmd/xl-v1-utils_test.go
  49. 3
      cmd/xl-v1.go
  50. 154
      pkg/errors/errors.go
  51. 120
      pkg/errors/errors_test.go

@ -22,7 +22,6 @@ import (
"net/http" "net/http"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -853,7 +852,6 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) {
return ErrNone return ErrNone
} }
err = errors.Cause(err)
// Verify if the underlying error is signature mismatch. // Verify if the underlying error is signature mismatch.
switch err { switch err {
case errSignatureMismatch: case errSignatureMismatch:

@ -34,7 +34,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio-go/pkg/set" "github.com/minio/minio-go/pkg/set"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -45,7 +44,6 @@ func enforceBucketPolicy(ctx context.Context, bucket, action, resource, referer,
// Verify if bucket actually exists // Verify if bucket actually exists
objAPI := newObjectLayerFn() objAPI := newObjectLayerFn()
if err := checkBucketExist(ctx, bucket, objAPI); err != nil { if err := checkBucketExist(ctx, bucket, objAPI); err != nil {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case BucketNameInvalid: case BucketNameInvalid:
// Return error for invalid bucket name. // Return error for invalid bucket name.
@ -357,7 +355,7 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter,
deletedObjects = append(deletedObjects, object) deletedObjects = append(deletedObjects, object)
continue continue
} }
if _, ok := errors.Cause(err).(ObjectNotFound); ok { if _, ok := err.(ObjectNotFound); ok {
// If the object is not found it should be // If the object is not found it should be
// accounted as deleted as per S3 spec. // accounted as deleted as per S3 spec.
deletedObjects = append(deletedObjects, object) deletedObjects = append(deletedObjects, object)

@ -24,7 +24,6 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
xerrors "github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/event/target" "github.com/minio/minio/pkg/event/target"
xnet "github.com/minio/minio/pkg/net" xnet "github.com/minio/minio/pkg/net"
@ -72,7 +71,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
nConfig, err := readNotificationConfig(ctx, objAPI, bucketName) nConfig, err := readNotificationConfig(ctx, objAPI, bucketName)
if err != nil { if err != nil {
// Ignore errNoSuchNotifications to comply with AWS S3. // Ignore errNoSuchNotifications to comply with AWS S3.
if xerrors.Cause(err) != errNoSuchNotifications { if err != errNoSuchNotifications {
writeErrorResponse(w, toAPIErrorCode(err), r.URL) writeErrorResponse(w, toAPIErrorCode(err), r.URL)
return return
} }

@ -29,7 +29,6 @@ import (
mux "github.com/gorilla/mux" mux "github.com/gorilla/mux"
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/wildcard" "github.com/minio/minio/pkg/wildcard"
) )
@ -277,7 +276,6 @@ func (api objectAPIHandlers) PutBucketPolicyHandler(w http.ResponseWriter, r *ht
} }
if err = objAPI.SetBucketPolicy(ctx, bucket, policyInfo); err != nil { if err = objAPI.SetBucketPolicy(ctx, bucket, policyInfo); err != nil {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case NotImplemented: case NotImplemented:
// Return error for invalid bucket name. // Return error for invalid bucket name.

@ -26,7 +26,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -86,7 +85,7 @@ func initBucketPolicies(objAPI ObjectLayer) (*bucketPolicies, error) {
// List buckets to proceed loading all notification configuration. // List buckets to proceed loading all notification configuration.
buckets, err := objAPI.ListBuckets(context.Background()) buckets, err := objAPI.ListBuckets(context.Background())
if err != nil { if err != nil {
return nil, errors.Cause(err) return nil, err
} }
policies := make(map[string]policy.BucketAccessPolicy) policies := make(map[string]policy.BucketAccessPolicy)
@ -96,9 +95,9 @@ func initBucketPolicies(objAPI ObjectLayer) (*bucketPolicies, error) {
if pErr != nil { if pErr != nil {
// net.Dial fails for rpc client or any // net.Dial fails for rpc client or any
// other unexpected errors during net.Dial. // other unexpected errors during net.Dial.
if !errors.IsErrIgnored(pErr, errDiskNotFound) { if !IsErrIgnored(pErr, errDiskNotFound) {
if !isErrBucketPolicyNotFound(pErr) { if !isErrBucketPolicyNotFound(pErr) {
return nil, errors.Cause(pErr) return nil, pErr
} }
} }
// Continue to load other bucket policies if possible. // Continue to load other bucket policies if possible.
@ -126,7 +125,7 @@ func readBucketPolicyJSON(bucket string, objAPI ObjectLayer) (bucketPolicyReader
if isErrObjectNotFound(err) || isErrIncompleteBody(err) { if isErrObjectNotFound(err) || isErrIncompleteBody(err) {
return nil, PolicyNotFound{Bucket: bucket} return nil, PolicyNotFound{Bucket: bucket}
} }
return nil, errors.Cause(err) return nil, err
} }
return &buffer, nil return &buffer, nil
@ -156,7 +155,6 @@ func removeBucketPolicy(ctx context.Context, bucket string, objAPI ObjectLayer)
policyPath := pathJoin(bucketConfigPrefix, bucket, bucketPolicyConfig) policyPath := pathJoin(bucketConfigPrefix, bucket, bucketPolicyConfig)
err := objAPI.DeleteObject(ctx, minioMetaBucket, policyPath) err := objAPI.DeleteObject(ctx, minioMetaBucket, policyPath)
if err != nil { if err != nil {
err = errors.Cause(err)
if _, ok := err.(ObjectNotFound); ok { if _, ok := err.(ObjectNotFound); ok {
return BucketPolicyNotFound{Bucket: bucket} return BucketPolicyNotFound{Bucket: bucket}
} }
@ -177,11 +175,11 @@ func writeBucketPolicy(ctx context.Context, bucket string, objAPI ObjectLayer, b
hashReader, err := hash.NewReader(bytes.NewReader(buf), int64(len(buf)), "", getSHA256Hash(buf)) hashReader, err := hash.NewReader(bytes.NewReader(buf), int64(len(buf)), "", getSHA256Hash(buf))
if err != nil { if err != nil {
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
return errors.Cause(err) return err
} }
if _, err = objAPI.PutObject(ctx, minioMetaBucket, policyPath, hashReader, nil); err != nil { if _, err = objAPI.PutObject(ctx, minioMetaBucket, policyPath, hashReader, nil); err != nil {
return errors.Cause(err) return err
} }
return nil return nil
} }

@ -30,7 +30,6 @@ import (
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/disk" "github.com/minio/minio/pkg/disk"
errors2 "github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
"github.com/minio/minio/pkg/lock" "github.com/minio/minio/pkg/lock"
) )
@ -279,7 +278,7 @@ func (cfs *cacheFSObjects) Put(ctx context.Context, bucket, object string, data
} }
_, err := cfs.PutObject(ctx, bucket, object, data, metadata) _, err := cfs.PutObject(ctx, bucket, object, data, metadata)
// if err is due to disk being offline , mark cache drive as offline // if err is due to disk being offline , mark cache drive as offline
if errors2.IsErr(err, baseErrs...) { if IsErr(err, baseErrs...) {
cfs.setOnline(false) cfs.setOnline(false)
} }
return err return err

@ -32,7 +32,6 @@ import (
"github.com/djherbis/atime" "github.com/djherbis/atime"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
errors2 "github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/wildcard" "github.com/minio/minio/pkg/wildcard"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
@ -104,8 +103,8 @@ type CacheObjectLayer interface {
// backendDownError returns true if err is due to backend failure or faulty disk if in server mode // backendDownError returns true if err is due to backend failure or faulty disk if in server mode
func backendDownError(err error) bool { func backendDownError(err error) bool {
_, backendDown := errors2.Cause(err).(BackendDown) _, backendDown := err.(BackendDown)
return backendDown || errors2.IsErr(err, baseErrs...) return backendDown || IsErr(err, baseErrs...)
} }
// get cache disk where object is currently cached for a GET operation. If object does not exist at that location, // get cache disk where object is currently cached for a GET operation. If object does not exist at that location,
@ -192,7 +191,7 @@ func (c cacheObjects) GetObject(ctx context.Context, bucket, object string, star
objInfo, err := GetObjectInfoFn(ctx, bucket, object) objInfo, err := GetObjectInfoFn(ctx, bucket, object)
backendDown := backendDownError(err) backendDown := backendDownError(err)
if err != nil && !backendDown { if err != nil && !backendDown {
if _, ok := errors2.Cause(err).(ObjectNotFound); ok { if _, ok := err.(ObjectNotFound); ok {
// Delete the cached entry if backend object was deleted. // Delete the cached entry if backend object was deleted.
dcache.Delete(ctx, bucket, object) dcache.Delete(ctx, bucket, object)
} }
@ -256,7 +255,7 @@ func (c cacheObjects) GetObjectInfo(ctx context.Context, bucket, object string)
} }
objInfo, err := getObjectInfoFn(ctx, bucket, object) objInfo, err := getObjectInfoFn(ctx, bucket, object)
if err != nil { if err != nil {
if _, ok := errors2.Cause(err).(ObjectNotFound); ok { if _, ok := err.(ObjectNotFound); ok {
// Delete the cached entry if backend object was deleted. // Delete the cached entry if backend object was deleted.
dcache.Delete(ctx, bucket, object) dcache.Delete(ctx, bucket, object)
return ObjectInfo{}, err return ObjectInfo{}, err
@ -379,7 +378,7 @@ func (c cacheObjects) listCacheObjects(ctx context.Context, bucket, prefix, mark
fs, err := c.cache.getCacheFS(ctx, bucket, entry) fs, err := c.cache.getCacheFS(ctx, bucket, entry)
if err != nil { if err != nil {
// Ignore errFileNotFound // Ignore errFileNotFound
if errors2.Cause(err) == errFileNotFound { if err == errFileNotFound {
continue continue
} }
return result, toObjectErr(err, bucket, prefix) return result, toObjectErr(err, bucket, prefix)
@ -387,7 +386,7 @@ func (c cacheObjects) listCacheObjects(ctx context.Context, bucket, prefix, mark
objInfo, err = fs.getObjectInfo(ctx, bucket, entry) objInfo, err = fs.getObjectInfo(ctx, bucket, entry)
if err != nil { if err != nil {
// Ignore errFileNotFound // Ignore errFileNotFound
if errors2.Cause(err) == errFileNotFound { if err == errFileNotFound {
continue continue
} }
return result, toObjectErr(err, bucket, prefix) return result, toObjectErr(err, bucket, prefix)

@ -27,7 +27,6 @@ import (
"encoding/hex" "encoding/hex"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
sha256 "github.com/minio/sha256-simd" sha256 "github.com/minio/sha256-simd"
) )
@ -303,7 +302,7 @@ func hasAnyErrors(errs []error) bool {
func countErrs(errs []error, err error) int { func countErrs(errs []error, err error) int {
var i = 0 var i = 0
for _, err1 := range errs { for _, err1 := range errs {
if errors.Cause(err1) == err { if err1 == err {
i++ i++
} }
} }
@ -644,17 +643,17 @@ func initFormatXL(ctx context.Context, storageDisks []StorageAPI, setCount, disk
func makeFormatXLMetaVolumes(disk StorageAPI) error { func makeFormatXLMetaVolumes(disk StorageAPI) error {
// Attempt to create `.minio.sys`. // Attempt to create `.minio.sys`.
if err := disk.MakeVol(minioMetaBucket); err != nil { if err := disk.MakeVol(minioMetaBucket); err != nil {
if !errors.IsErrIgnored(err, initMetaVolIgnoredErrs...) { if !IsErrIgnored(err, initMetaVolIgnoredErrs...) {
return err return err
} }
} }
if err := disk.MakeVol(minioMetaTmpBucket); err != nil { if err := disk.MakeVol(minioMetaTmpBucket); err != nil {
if !errors.IsErrIgnored(err, initMetaVolIgnoredErrs...) { if !IsErrIgnored(err, initMetaVolIgnoredErrs...) {
return err return err
} }
} }
if err := disk.MakeVol(minioMetaMultipartBucket); err != nil { if err := disk.MakeVol(minioMetaMultipartBucket); err != nil {
if !errors.IsErrIgnored(err, initMetaVolIgnoredErrs...) { if !IsErrIgnored(err, initMetaVolIgnoredErrs...) {
return err return err
} }
} }

@ -22,8 +22,6 @@ import (
"os" "os"
"reflect" "reflect"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
// Test get offline/online uuids. // Test get offline/online uuids.
@ -114,7 +112,7 @@ func TestFixFormatV3(t *testing.T) {
newFormats, errs := loadFormatXLAll(storageDisks) newFormats, errs := loadFormatXLAll(storageDisks)
for _, err := range errs { for _, err := range errs {
if err != nil && errors.Cause(err) != errUnformattedDisk { if err != nil && err != errUnformattedDisk {
t.Fatal(err) t.Fatal(err)
} }
} }

@ -24,7 +24,6 @@ import (
"runtime" "runtime"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/lock" "github.com/minio/minio/pkg/lock"
) )
@ -175,7 +174,6 @@ func fsStat(ctx context.Context, statLoc string) (os.FileInfo, error) {
func fsStatVolume(ctx context.Context, volume string) (os.FileInfo, error) { func fsStatVolume(ctx context.Context, volume string) (os.FileInfo, error) {
fi, err := fsStat(ctx, volume) fi, err := fsStat(ctx, volume)
if err != nil { if err != nil {
err = errors.Cause(err)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, errVolumeNotFound return nil, errVolumeNotFound
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
@ -200,7 +198,6 @@ func osErrToFSFileErr(err error) error {
if err == nil { if err == nil {
return nil return nil
} }
err = errors.Cause(err)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errFileNotFound return errFileNotFound
} }

@ -25,7 +25,6 @@ import (
"path" "path"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/lock" "github.com/minio/minio/pkg/lock"
) )
@ -43,13 +42,13 @@ func TestFSRenameFile(t *testing.T) {
if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil { if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); errors.Cause(err) != errFileNotFound { if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != errFileNotFound {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRenameFile(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); errors.Cause(err) != errFileNameTooLong { if err = fsRenameFile(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); errors.Cause(err) != errFileNameTooLong { if err = fsRenameFile(context.Background(), pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
} }
@ -64,11 +63,11 @@ func TestFSStats(t *testing.T) {
// Setup test environment. // Setup test environment.
if err = fsMkdir(context.Background(), ""); errors.Cause(err) != errInvalidArgument { if err = fsMkdir(context.Background(), ""); err != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if err = fsMkdir(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); errors.Cause(err) != errFileNameTooLong { if err = fsMkdir(context.Background(), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -83,7 +82,7 @@ func TestFSStats(t *testing.T) {
// Seek back. // Seek back.
reader.Seek(0, 0) reader.Seek(0, 0)
if err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "success-file")); errors.Cause(err) != errVolumeExists { if err = fsMkdir(context.Background(), pathJoin(path, "success-vol", "success-file")); err != errVolumeExists {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -171,11 +170,11 @@ func TestFSStats(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
if testCase.srcPath != "" { if testCase.srcPath != "" {
if _, err := fsStatFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, if _, err := fsStatFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol,
testCase.srcPath)); errors.Cause(err) != testCase.expectedErr { testCase.srcPath)); err != testCase.expectedErr {
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} else { } else {
if _, err := fsStatVolume(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol)); errors.Cause(err) != testCase.expectedErr { if _, err := fsStatVolume(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol)); err != testCase.expectedErr {
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
@ -194,11 +193,11 @@ func TestFSCreateAndOpen(t *testing.T) {
t.Fatalf("Unable to create directory, %s", err) t.Fatalf("Unable to create directory, %s", err)
} }
if _, err = fsCreateFile(context.Background(), "", nil, nil, 0); errors.Cause(err) != errInvalidArgument { if _, err = fsCreateFile(context.Background(), "", nil, nil, 0); err != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if _, _, err = fsOpenFile(context.Background(), "", -1); errors.Cause(err) != errInvalidArgument { if _, _, err = fsOpenFile(context.Background(), "", -1); err != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -232,17 +231,17 @@ func TestFSCreateAndOpen(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
_, err = fsCreateFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), reader, nil, 0) _, err = fsCreateFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), reader, nil, 0)
if errors.Cause(err) != testCase.expectedErr { if err != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
_, _, err = fsOpenFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), 0) _, _, err = fsOpenFile(context.Background(), pathJoin(path, testCase.srcVol, testCase.srcPath), 0)
if errors.Cause(err) != testCase.expectedErr { if err != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
// Attempt to open a directory. // Attempt to open a directory.
if _, _, err = fsOpenFile(context.Background(), pathJoin(path), 0); errors.Cause(err) != errIsNotRegular { if _, _, err = fsOpenFile(context.Background(), pathJoin(path), 0); err != errIsNotRegular {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
} }
@ -344,7 +343,7 @@ func TestFSDeletes(t *testing.T) {
} }
for i, testCase := range testCases { for i, testCase := range testCases {
if err = fsDeleteFile(context.Background(), testCase.basePath, pathJoin(testCase.basePath, testCase.srcVol, testCase.srcPath)); errors.Cause(err) != testCase.expectedErr { if err = fsDeleteFile(context.Background(), testCase.basePath, pathJoin(testCase.basePath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
@ -478,11 +477,11 @@ func TestFSRemoves(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
if testCase.srcPath != "" { if testCase.srcPath != "" {
if err = fsRemoveFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); errors.Cause(err) != testCase.expectedErr { if err = fsRemoveFile(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} else { } else {
if err = fsRemoveDir(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); errors.Cause(err) != testCase.expectedErr { if err = fsRemoveDir(context.Background(), pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr {
t.Error(err) t.Error(err)
} }
} }
@ -492,11 +491,11 @@ func TestFSRemoves(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRemoveAll(context.Background(), ""); errors.Cause(err) != errInvalidArgument { if err = fsRemoveAll(context.Background(), ""); err != errInvalidArgument {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRemoveAll(context.Background(), "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); errors.Cause(err) != errFileNameTooLong { if err = fsRemoveAll(context.Background(), "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); err != errFileNameTooLong {
t.Fatal(err) t.Fatal(err)
} }
} }

@ -30,7 +30,6 @@ import (
"time" "time"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
mioutil "github.com/minio/minio/pkg/ioutil" mioutil "github.com/minio/minio/pkg/ioutil"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
@ -304,7 +303,7 @@ func (fs *FSObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID
// Just check if the uploadID exists to avoid copy if it doesn't. // Just check if the uploadID exists to avoid copy if it doesn't.
_, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile)) _, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile))
if err != nil { if err != nil {
if errors.Cause(err) == errFileNotFound || errors.Cause(err) == errFileAccessDenied { if err == errFileNotFound || err == errFileAccessDenied {
return pi, InvalidUploadID{UploadID: uploadID} return pi, InvalidUploadID{UploadID: uploadID}
} }
return pi, toObjectErr(err, bucket, object) return pi, toObjectErr(err, bucket, object)
@ -384,7 +383,7 @@ func (fs *FSObjects) ListObjectParts(ctx context.Context, bucket, object, upload
uploadIDDir := fs.getUploadIDDir(bucket, object, uploadID) uploadIDDir := fs.getUploadIDDir(bucket, object, uploadID)
_, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile)) _, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile))
if err != nil { if err != nil {
if errors.Cause(err) == errFileNotFound || errors.Cause(err) == errFileAccessDenied { if err == errFileNotFound || err == errFileAccessDenied {
return result, InvalidUploadID{UploadID: uploadID} return result, InvalidUploadID{UploadID: uploadID}
} }
return result, toObjectErr(err, bucket, object) return result, toObjectErr(err, bucket, object)
@ -498,7 +497,7 @@ func (fs *FSObjects) CompleteMultipartUpload(ctx context.Context, bucket string,
// Just check if the uploadID exists to avoid copy if it doesn't. // Just check if the uploadID exists to avoid copy if it doesn't.
_, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile)) _, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile))
if err != nil { if err != nil {
if errors.Cause(err) == errFileNotFound || errors.Cause(err) == errFileAccessDenied { if err == errFileNotFound || err == errFileAccessDenied {
return oi, InvalidUploadID{UploadID: uploadID} return oi, InvalidUploadID{UploadID: uploadID}
} }
return oi, toObjectErr(err, bucket, object) return oi, toObjectErr(err, bucket, object)
@ -523,7 +522,7 @@ func (fs *FSObjects) CompleteMultipartUpload(ctx context.Context, bucket string,
var fi os.FileInfo var fi os.FileInfo
fi, err = fsStatFile(ctx, partPath) fi, err = fsStatFile(ctx, partPath)
if err != nil { if err != nil {
if errors.Cause(err) == errFileNotFound || errors.Cause(err) == errFileAccessDenied { if err == errFileNotFound || err == errFileAccessDenied {
return oi, InvalidPart{} return oi, InvalidPart{}
} }
return oi, err return oi, err
@ -698,7 +697,7 @@ func (fs *FSObjects) AbortMultipartUpload(ctx context.Context, bucket, object, u
// Just check if the uploadID exists to avoid copy if it doesn't. // Just check if the uploadID exists to avoid copy if it doesn't.
_, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile)) _, err := fsStatFile(ctx, pathJoin(uploadIDDir, fs.metaJSONFile))
if err != nil { if err != nil {
if errors.Cause(err) == errFileNotFound || errors.Cause(err) == errFileAccessDenied { if err == errFileNotFound || err == errFileAccessDenied {
return InvalidUploadID{UploadID: uploadID} return InvalidUploadID{UploadID: uploadID}
} }
return toObjectErr(err, bucket, object) return toObjectErr(err, bucket, object)

@ -23,8 +23,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
"github.com/minio/minio/pkg/errors"
) )
// Tests cleanup multipart uploads for filesystem backend. // Tests cleanup multipart uploads for filesystem backend.
@ -60,7 +58,6 @@ func TestFSCleanupMultipartUploadsInRoutine(t *testing.T) {
// Check if upload id was already purged. // Check if upload id was already purged.
if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil {
err = errors.Cause(err)
if _, ok := err.(InvalidUploadID); !ok { if _, ok := err.(InvalidUploadID); !ok {
t.Fatal("Unexpected err: ", err) t.Fatal("Unexpected err: ", err)
} }
@ -85,7 +82,7 @@ func TestNewMultipartUploadFaultyDisk(t *testing.T) {
// Test with disk removed. // Test with disk removed.
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if _, err := fs.NewMultipartUpload(context.Background(), bucketName, objectName, map[string]string{"X-Amz-Meta-xid": "3f"}); err != nil { if _, err := fs.NewMultipartUpload(context.Background(), bucketName, objectName, map[string]string{"X-Amz-Meta-xid": "3f"}); err != nil {
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error ", err) t.Fatal("Unexpected error ", err)
} }
} }
@ -123,7 +120,7 @@ func TestPutObjectPartFaultyDisk(t *testing.T) {
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
_, err = fs.PutObjectPart(context.Background(), bucketName, objectName, uploadID, 1, mustGetHashReader(t, bytes.NewReader(data), dataLen, md5Hex, sha256sum)) _, err = fs.PutObjectPart(context.Background(), bucketName, objectName, uploadID, 1, mustGetHashReader(t, bytes.NewReader(data), dataLen, md5Hex, sha256sum))
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error ", err) t.Fatal("Unexpected error ", err)
} }
} }
@ -154,7 +151,7 @@ func TestCompleteMultipartUploadFaultyDisk(t *testing.T) {
parts := []CompletePart{{PartNumber: 1, ETag: md5Hex}} parts := []CompletePart{{PartNumber: 1, ETag: md5Hex}}
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if _, err := fs.CompleteMultipartUpload(context.Background(), bucketName, objectName, uploadID, parts); err != nil { if _, err := fs.CompleteMultipartUpload(context.Background(), bucketName, objectName, uploadID, parts); err != nil {
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error ", err) t.Fatal("Unexpected error ", err)
} }
} }
@ -249,7 +246,7 @@ func TestListMultipartUploadsFaultyDisk(t *testing.T) {
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if _, err := fs.ListMultipartUploads(context.Background(), bucketName, objectName, "", "", "", 1000); err != nil { if _, err := fs.ListMultipartUploads(context.Background(), bucketName, objectName, "", "", "", 1000); err != nil {
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error ", err) t.Fatal("Unexpected error ", err)
} }
} }

@ -31,7 +31,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
"github.com/minio/minio/pkg/lock" "github.com/minio/minio/pkg/lock"
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
@ -527,7 +526,7 @@ func (fs *FSObjects) getObject(ctx context.Context, bucket, object string, offse
func (fs *FSObjects) getObjectInfo(ctx context.Context, bucket, object string) (oi ObjectInfo, e error) { func (fs *FSObjects) getObjectInfo(ctx context.Context, bucket, object string) (oi ObjectInfo, e error) {
fsMeta := fsMetaV1{} fsMeta := fsMetaV1{}
fi, err := fsStatDir(ctx, pathJoin(fs.fsPath, bucket, object)) fi, err := fsStatDir(ctx, pathJoin(fs.fsPath, bucket, object))
if err != nil && errors.Cause(err) != errFileAccessDenied { if err != nil && err != errFileAccessDenied {
return oi, toObjectErr(err, bucket, object) return oi, toObjectErr(err, bucket, object)
} }
if fi != nil { if fi != nil {
@ -552,7 +551,7 @@ func (fs *FSObjects) getObjectInfo(ctx context.Context, bucket, object string) (
// `fs.json` can be empty due to previously failed // `fs.json` can be empty due to previously failed
// PutObject() transaction, if we arrive at such // PutObject() transaction, if we arrive at such
// a situation we just ignore and continue. // a situation we just ignore and continue.
if errors.Cause(rerr) != io.EOF { if rerr != io.EOF {
return oi, toObjectErr(rerr, bucket, object) return oi, toObjectErr(rerr, bucket, object)
} }
} }
@ -807,7 +806,7 @@ func (fs *FSObjects) DeleteObject(ctx context.Context, bucket, object string) er
if bucket != minioMetaBucket { if bucket != minioMetaBucket {
// Delete the metadata object. // Delete the metadata object.
err := fsDeleteFile(ctx, minioMetaBucketDir, fsMetaPath) err := fsDeleteFile(ctx, minioMetaBucketDir, fsMetaPath)
if err != nil && errors.Cause(err) != errFileNotFound { if err != nil && err != errFileNotFound {
return toObjectErr(err, bucket, object) return toObjectErr(err, bucket, object)
} }
} }
@ -980,7 +979,7 @@ func (fs *FSObjects) ListObjects(ctx context.Context, bucket, prefix, marker, de
// For any walk error return right away. // For any walk error return right away.
if walkResult.err != nil { if walkResult.err != nil {
// File not found is a valid case. // File not found is a valid case.
if errors.Cause(walkResult.err) == errFileNotFound { if walkResult.err == errFileNotFound {
return loi, nil return loi, nil
} }
return loi, toObjectErr(walkResult.err, bucket, prefix) return loi, toObjectErr(walkResult.err, bucket, prefix)
@ -1020,7 +1019,8 @@ func (fs *FSObjects) ListObjects(ctx context.Context, bucket, prefix, marker, de
// ReloadFormat - no-op for fs, Valid only for XL. // ReloadFormat - no-op for fs, Valid only for XL.
func (fs *FSObjects) ReloadFormat(ctx context.Context, dryRun bool) error { func (fs *FSObjects) ReloadFormat(ctx context.Context, dryRun bool) error {
return errors.Trace(NotImplemented{}) logger.LogIf(ctx, NotImplemented{})
return NotImplemented{}
} }
// HealFormat - no-op for fs, Valid only for XL. // HealFormat - no-op for fs, Valid only for XL.

@ -23,8 +23,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
// Tests for if parent directory is object // Tests for if parent directory is object
@ -181,7 +179,7 @@ func TestFSGetBucketInfo(t *testing.T) {
// Test with inexistant bucket // Test with inexistant bucket
_, err = fs.GetBucketInfo(context.Background(), "a") _, err = fs.GetBucketInfo(context.Background(), "a")
if !isSameType(errors.Cause(err), BucketNameInvalid{}) { if !isSameType(err, BucketNameInvalid{}) {
t.Fatal("BucketNameInvalid error not returned") t.Fatal("BucketNameInvalid error not returned")
} }
@ -189,7 +187,7 @@ func TestFSGetBucketInfo(t *testing.T) {
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
_, err = fs.GetBucketInfo(context.Background(), bucketName) _, err = fs.GetBucketInfo(context.Background(), bucketName)
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("BucketNotFound error not returned") t.Fatal("BucketNotFound error not returned")
} }
} }
@ -212,7 +210,7 @@ func TestFSPutObject(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Unexpected should fail here, bucket doesn't exist") t.Fatal("Unexpected should fail here, bucket doesn't exist")
} }
if _, ok := errors.Cause(err).(BucketNotFound); !ok { if _, ok := err.(BucketNotFound); !ok {
t.Fatalf("Expected error type BucketNotFound, got %#v", err) t.Fatalf("Expected error type BucketNotFound, got %#v", err)
} }
@ -221,7 +219,7 @@ func TestFSPutObject(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Unexpected should fail here, bucket doesn't exist") t.Fatal("Unexpected should fail here, bucket doesn't exist")
} }
if _, ok := errors.Cause(err).(BucketNotFound); !ok { if _, ok := err.(BucketNotFound); !ok {
t.Fatalf("Expected error type BucketNotFound, got %#v", err) t.Fatalf("Expected error type BucketNotFound, got %#v", err)
} }
@ -233,7 +231,7 @@ func TestFSPutObject(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Unexpected should fail here, backend corruption occurred") t.Fatal("Unexpected should fail here, backend corruption occurred")
} }
if nerr, ok := errors.Cause(err).(PrefixAccessDenied); !ok { if nerr, ok := err.(PrefixAccessDenied); !ok {
t.Fatalf("Expected PrefixAccessDenied, got %#v", err) t.Fatalf("Expected PrefixAccessDenied, got %#v", err)
} else { } else {
if nerr.Bucket != "bucket" { if nerr.Bucket != "bucket" {
@ -248,7 +246,7 @@ func TestFSPutObject(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Unexpected should fail here, backned corruption occurred") t.Fatal("Unexpected should fail here, backned corruption occurred")
} }
if nerr, ok := errors.Cause(err).(PrefixAccessDenied); !ok { if nerr, ok := err.(PrefixAccessDenied); !ok {
t.Fatalf("Expected PrefixAccessDenied, got %#v", err) t.Fatalf("Expected PrefixAccessDenied, got %#v", err)
} else { } else {
if nerr.Bucket != "bucket" { if nerr.Bucket != "bucket" {
@ -275,19 +273,19 @@ func TestFSDeleteObject(t *testing.T) {
obj.PutObject(context.Background(), bucketName, objectName, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil) obj.PutObject(context.Background(), bucketName, objectName, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
// Test with invalid bucket name // Test with invalid bucket name
if err := fs.DeleteObject(context.Background(), "fo", objectName); !isSameType(errors.Cause(err), BucketNameInvalid{}) { if err := fs.DeleteObject(context.Background(), "fo", objectName); !isSameType(err, BucketNameInvalid{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with bucket does not exist // Test with bucket does not exist
if err := fs.DeleteObject(context.Background(), "foobucket", "fooobject"); !isSameType(errors.Cause(err), BucketNotFound{}) { if err := fs.DeleteObject(context.Background(), "foobucket", "fooobject"); !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with invalid object name // Test with invalid object name
if err := fs.DeleteObject(context.Background(), bucketName, "\\"); !isSameType(errors.Cause(err), ObjectNameInvalid{}) { if err := fs.DeleteObject(context.Background(), bucketName, "\\"); !isSameType(err, ObjectNameInvalid{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with object does not exist. // Test with object does not exist.
if err := fs.DeleteObject(context.Background(), bucketName, "foooobject"); !isSameType(errors.Cause(err), ObjectNotFound{}) { if err := fs.DeleteObject(context.Background(), bucketName, "foooobject"); !isSameType(err, ObjectNotFound{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with valid condition // Test with valid condition
@ -298,7 +296,7 @@ func TestFSDeleteObject(t *testing.T) {
// Delete object should err disk not found. // Delete object should err disk not found.
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if err := fs.DeleteObject(context.Background(), bucketName, objectName); err != nil { if err := fs.DeleteObject(context.Background(), bucketName, objectName); err != nil {
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
} }
@ -321,11 +319,11 @@ func TestFSDeleteBucket(t *testing.T) {
} }
// Test with an invalid bucket name // Test with an invalid bucket name
if err = fs.DeleteBucket(context.Background(), "fo"); !isSameType(errors.Cause(err), BucketNameInvalid{}) { if err = fs.DeleteBucket(context.Background(), "fo"); !isSameType(err, BucketNameInvalid{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with an inexistant bucket // Test with an inexistant bucket
if err = fs.DeleteBucket(context.Background(), "foobucket"); !isSameType(errors.Cause(err), BucketNotFound{}) { if err = fs.DeleteBucket(context.Background(), "foobucket"); !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
// Test with a valid case // Test with a valid case
@ -338,7 +336,7 @@ func TestFSDeleteBucket(t *testing.T) {
// Delete bucket should get error disk not found. // Delete bucket should get error disk not found.
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if err = fs.DeleteBucket(context.Background(), bucketName); err != nil { if err = fs.DeleteBucket(context.Background(), bucketName); err != nil {
if !isSameType(errors.Cause(err), BucketNotFound{}) { if !isSameType(err, BucketNotFound{}) {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
} }
@ -381,7 +379,7 @@ func TestFSListBuckets(t *testing.T) {
fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix()) fs.fsPath = filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
if _, err := fs.ListBuckets(context.Background()); err != nil { if _, err := fs.ListBuckets(context.Background()); err != nil {
if errors.Cause(err) != errDiskNotFound { if err != errDiskNotFound {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
} }
@ -389,7 +387,7 @@ func TestFSListBuckets(t *testing.T) {
longPath := fmt.Sprintf("%0256d", 1) longPath := fmt.Sprintf("%0256d", 1)
fs.fsPath = longPath fs.fsPath = longPath
if _, err := fs.ListBuckets(context.Background()); err != nil { if _, err := fs.ListBuckets(context.Background()); err != nil {
if errors.Cause(err) != errFileNameTooLong { if err != errFileNameTooLong {
t.Fatal("Unexpected error: ", err) t.Fatal("Unexpected error: ", err)
} }
} }
@ -402,7 +400,7 @@ func TestFSHealObject(t *testing.T) {
obj := initFSObjects(disk, t) obj := initFSObjects(disk, t)
_, err := obj.HealObject(context.Background(), "bucket", "object", false) _, err := obj.HealObject(context.Background(), "bucket", "object", false)
if err == nil || !isSameType(errors.Cause(err), NotImplemented{}) { if err == nil || !isSameType(err, NotImplemented{}) {
t.Fatalf("Heal Object should return NotImplemented error ") t.Fatalf("Heal Object should return NotImplemented error ")
} }
} }
@ -414,7 +412,7 @@ func TestFSListObjectsHeal(t *testing.T) {
obj := initFSObjects(disk, t) obj := initFSObjects(disk, t)
_, err := obj.ListObjectsHeal(context.Background(), "bucket", "prefix", "marker", "delimiter", 1000) _, err := obj.ListObjectsHeal(context.Background(), "bucket", "prefix", "marker", "delimiter", 1000)
if err == nil || !isSameType(errors.Cause(err), NotImplemented{}) { if err == nil || !isSameType(err, NotImplemented{}) {
t.Fatalf("Heal Object should return NotImplemented error ") t.Fatalf("Heal Object should return NotImplemented error ")
} }
} }

@ -37,7 +37,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
sha256 "github.com/minio/sha256-simd" sha256 "github.com/minio/sha256-simd"
@ -714,7 +713,7 @@ func (a *azureObjects) checkUploadIDExists(ctx context.Context, bucketName, obje
Bucket: bucketName, Bucket: bucketName,
Object: objectName, Object: objectName,
} }
if errors.Cause(err) == oerr { if err == oerr {
logger.LogIf(ctx, minio.InvalidUploadID{UploadID: uploadID}) logger.LogIf(ctx, minio.InvalidUploadID{UploadID: uploadID})
err = minio.InvalidUploadID{ err = minio.InvalidUploadID{
UploadID: uploadID, UploadID: uploadID,

@ -25,7 +25,6 @@ import (
"github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/azure-sdk-for-go/storage"
minio "github.com/minio/minio/cmd" minio "github.com/minio/minio/cmd"
"github.com/minio/minio/pkg/errors"
) )
// Test canonical metadata. // Test canonical metadata.
@ -67,7 +66,7 @@ func TestS3MetaToAzureProperties(t *testing.T) {
"invalid--meta": "value", "invalid--meta": "value",
} }
_, _, err = s3MetaToAzureProperties(context.Background(), headers) _, _, err = s3MetaToAzureProperties(context.Background(), headers)
if err = errors.Cause(err); err != nil { if err != nil {
if _, ok := err.(minio.UnsupportedMetadata); !ok { if _, ok := err.(minio.UnsupportedMetadata); !ok {
t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err) t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err)
} }

@ -26,7 +26,6 @@ import (
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
minio "github.com/minio/minio/cmd" minio "github.com/minio/minio/cmd"
"github.com/minio/minio/pkg/errors"
) )
func ossErrResponse(code string) error { func ossErrResponse(code string) error {
@ -104,8 +103,8 @@ func TestOSSToObjectError(t *testing.T) {
for i, tc := range testCases { for i, tc := range testCases {
actualErr := ossToObjectError(tc.inputErr, tc.bucket, tc.object) actualErr := ossToObjectError(tc.inputErr, tc.bucket, tc.object)
if e, ok := actualErr.(*errors.Error); ok && e.Cause != tc.expectedErr { if actualErr != nil && tc.expectedErr != nil && actualErr.Error() != tc.expectedErr.Error() {
t.Errorf("Test case %d: Expected error '%v' but received error '%v'", i+1, tc.expectedErr, e.Cause) t.Errorf("Test case %d: Expected error '%v' but received error '%v'", i+1, tc.expectedErr, actualErr)
} }
} }
} }
@ -118,7 +117,7 @@ func TestS3MetaToOSSOptions(t *testing.T) {
"x-amz-meta-invalid_meta": "value", "x-amz-meta-invalid_meta": "value",
} }
_, err = appendS3MetaToOSSOptions(context.Background(), nil, headers) _, err = appendS3MetaToOSSOptions(context.Background(), nil, headers)
if err = errors.Cause(err); err != nil { if err != nil {
if _, ok := err.(minio.UnsupportedMetadata); !ok { if _, ok := err.(minio.UnsupportedMetadata); !ok {
t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err) t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err)
} }

@ -21,7 +21,6 @@ import (
"testing" "testing"
miniogo "github.com/minio/minio-go" miniogo "github.com/minio/minio-go"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
minio "github.com/minio/minio/cmd" minio "github.com/minio/minio/cmd"
@ -110,17 +109,11 @@ func TestS3ToObjectError(t *testing.T) {
inputErr: fmt.Errorf("not a minio.ErrorResponse"), inputErr: fmt.Errorf("not a minio.ErrorResponse"),
expectedErr: fmt.Errorf("not a minio.ErrorResponse"), expectedErr: fmt.Errorf("not a minio.ErrorResponse"),
}, },
// Special test case for error value that is not of
// type (*Error)
{
inputErr: fmt.Errorf("not a *Error"),
expectedErr: fmt.Errorf("not a *Error"),
},
} }
for i, tc := range testCases { for i, tc := range testCases {
actualErr := minio.ErrorRespToObjectError(tc.inputErr, tc.bucket, tc.object) actualErr := minio.ErrorRespToObjectError(tc.inputErr, tc.bucket, tc.object)
if e, ok := actualErr.(*errors.Error); ok && e.Cause.Error() != tc.expectedErr.Error() { if actualErr != nil && tc.expectedErr != nil && actualErr.Error() != tc.expectedErr.Error() {
t.Errorf("Test case %d: Expected error %v but received error %v", i+1, tc.expectedErr, actualErr) t.Errorf("Test case %d: Expected error %v but received error %v", i+1, tc.expectedErr, actualErr)
} }
} }

@ -26,8 +26,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
// Tests validate bucket LocationConstraint. // Tests validate bucket LocationConstraint.
@ -117,7 +115,7 @@ func TestValidateFormFieldSize(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
err := validateFormFieldSize(context.Background(), testCase.header) err := validateFormFieldSize(context.Background(), testCase.header)
if err != nil { if err != nil {
if errors.Cause(err).Error() != testCase.err.Error() { if err.Error() != testCase.err.Error() {
t.Errorf("Test %d: Expected error %s, got %s", i+1, testCase.err, err) t.Errorf("Test %d: Expected error %s, got %s", i+1, testCase.err, err)
} }
} }

@ -18,8 +18,6 @@ package cmd
import ( import (
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
type lockStateCase struct { type lockStateCase struct {
@ -282,7 +280,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path} expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path}
if errors.Cause(actualErr) != expectedErr { if actualErr != expectedErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr)
} }
@ -302,7 +300,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedOpsErr := LockInfoOpsIDNotFound{testCases[0].volume, testCases[0].path, testCases[0].opsID} expectedOpsErr := LockInfoOpsIDNotFound{testCases[0].volume, testCases[0].path, testCases[0].opsID}
if errors.Cause(actualErr) != expectedOpsErr { if actualErr != expectedOpsErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedOpsErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedOpsErr, actualErr)
} }
@ -325,7 +323,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedBlockErr := LockInfoStateNotBlocked{testCases[0].volume, testCases[0].path, testCases[0].opsID} expectedBlockErr := LockInfoStateNotBlocked{testCases[0].volume, testCases[0].path, testCases[0].opsID}
if errors.Cause(actualErr) != expectedBlockErr { if actualErr != expectedBlockErr {
t.Fatalf("Errors mismatch: Expected: \"%s\", got: \"%s\"", expectedBlockErr, actualErr) t.Fatalf("Errors mismatch: Expected: \"%s\", got: \"%s\"", expectedBlockErr, actualErr)
} }
@ -346,7 +344,7 @@ func TestNsLockMapStatusBlockedToRunning(t *testing.T) {
} }
// invoking the method under test. // invoking the method under test.
actualErr = globalNSMutex.statusBlockedToRunning(param, testCase.lockSource, testCase.opsID, testCase.readLock) actualErr = globalNSMutex.statusBlockedToRunning(param, testCase.lockSource, testCase.opsID, testCase.readLock)
if errors.Cause(actualErr) != testCase.expectedErr { if actualErr != testCase.expectedErr {
t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr) t.Fatalf("Test %d: Errors mismatch: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, actualErr)
} }
// In case of no error proceed with validating the lock state information. // In case of no error proceed with validating the lock state information.
@ -465,7 +463,7 @@ func TestNsLockMapStatusNoneToBlocked(t *testing.T) {
testCases[0].opsID, testCases[0].readLock) testCases[0].opsID, testCases[0].readLock)
expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path} expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path}
if errors.Cause(actualErr) != expectedErr { if actualErr != expectedErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr)
} }
@ -509,7 +507,7 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
actualErr := globalNSMutex.deleteLockInfoEntryForOps(param, testCases[0].opsID) actualErr := globalNSMutex.deleteLockInfoEntryForOps(param, testCases[0].opsID)
expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path} expectedErr := LockInfoVolPathMissing{testCases[0].volume, testCases[0].path}
if errors.Cause(actualErr) != expectedErr { if actualErr != expectedErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedErr, actualErr)
} }
@ -528,7 +526,7 @@ func TestNsLockMapDeleteLockInfoEntryForOps(t *testing.T) {
actualErr = globalNSMutex.deleteLockInfoEntryForOps(param, "non-existent-OpsID") actualErr = globalNSMutex.deleteLockInfoEntryForOps(param, "non-existent-OpsID")
expectedOpsIDErr := LockInfoOpsIDNotFound{param.volume, param.path, "non-existent-OpsID"} expectedOpsIDErr := LockInfoOpsIDNotFound{param.volume, param.path, "non-existent-OpsID"}
if errors.Cause(actualErr) != expectedOpsIDErr { if actualErr != expectedOpsIDErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedOpsIDErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedOpsIDErr, actualErr)
} }
// case - 4. // case - 4.
@ -592,7 +590,7 @@ func TestNsLockMapDeleteLockInfoEntryForVolumePath(t *testing.T) {
param := nsParam{testCases[0].volume, testCases[0].path} param := nsParam{testCases[0].volume, testCases[0].path}
actualErr := globalNSMutex.deleteLockInfoEntryForVolumePath(param) actualErr := globalNSMutex.deleteLockInfoEntryForVolumePath(param)
expectedNilErr := LockInfoVolPathMissing{param.volume, param.path} expectedNilErr := LockInfoVolPathMissing{param.volume, param.path}
if errors.Cause(actualErr) != expectedNilErr { if actualErr != expectedNilErr {
t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedNilErr, actualErr) t.Fatalf("Errors mismatch: Expected \"%s\", got \"%s\"", expectedNilErr, actualErr)
} }

@ -27,7 +27,6 @@ import (
"sync" "sync"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
xerrors "github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
xnet "github.com/minio/minio/pkg/net" xnet "github.com/minio/minio/pkg/net"
@ -183,7 +182,7 @@ func (sys *NotificationSys) initListeners(ctx context.Context, objAPI ObjectLaye
defer objLock.Unlock() defer objLock.Unlock()
reader, err := readConfig(ctx, objAPI, configFile) reader, err := readConfig(ctx, objAPI, configFile)
if err != nil && !xerrors.IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) { if err != nil && !IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) {
return err return err
} }
@ -263,7 +262,7 @@ func (sys *NotificationSys) Init(objAPI ObjectLayer) error {
ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{BucketName: bucket.Name}) ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{BucketName: bucket.Name})
config, err := readNotificationConfig(ctx, objAPI, bucket.Name) config, err := readNotificationConfig(ctx, objAPI, bucket.Name)
if err != nil { if err != nil {
if !xerrors.IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) { if !IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) {
return err return err
} }
} else { } else {
@ -551,7 +550,7 @@ func SaveListener(objAPI ObjectLayer, bucketName string, eventNames []event.Name
defer objLock.Unlock() defer objLock.Unlock()
reader, err := readConfig(ctx, objAPI, configFile) reader, err := readConfig(ctx, objAPI, configFile)
if err != nil && !xerrors.IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) { if err != nil && !IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) {
return err return err
} }
@ -602,7 +601,7 @@ func RemoveListener(objAPI ObjectLayer, bucketName string, targetID event.Target
defer objLock.Unlock() defer objLock.Unlock()
reader, err := readConfig(ctx, objAPI, configFile) reader, err := readConfig(ctx, objAPI, configFile)
if err != nil && !xerrors.IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) { if err != nil && !IsErrIgnored(err, errDiskNotFound, errNoSuchNotifications) {
return err return err
} }

@ -19,19 +19,12 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"github.com/minio/minio/pkg/errors"
) )
// Converts underlying storage error. Convenience function written to // Converts underlying storage error. Convenience function written to
// handle all cases where we have known types of errors returned by // handle all cases where we have known types of errors returned by
// underlying storage layer. // underlying storage layer.
func toObjectErr(err error, params ...string) error { func toObjectErr(err error, params ...string) error {
e, ok := err.(*errors.Error)
if ok {
err = e.Cause
}
switch err { switch err {
case errVolumeNotFound: case errVolumeNotFound:
if len(params) >= 1 { if len(params) >= 1 {
@ -96,10 +89,6 @@ func toObjectErr(err error, params ...string) error {
case io.ErrUnexpectedEOF, io.ErrShortWrite: case io.ErrUnexpectedEOF, io.ErrShortWrite:
err = IncompleteBody{} err = IncompleteBody{}
} }
if ok {
e.Cause = err
return e
}
return err return err
} }
@ -400,7 +389,6 @@ func (e BackendDown) Error() string {
// isErrIncompleteBody - Check if error type is IncompleteBody. // isErrIncompleteBody - Check if error type is IncompleteBody.
func isErrIncompleteBody(err error) bool { func isErrIncompleteBody(err error) bool {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case IncompleteBody: case IncompleteBody:
return true return true
@ -410,7 +398,6 @@ func isErrIncompleteBody(err error) bool {
// isErrBucketPolicyNotFound - Check if error type is BucketPolicyNotFound. // isErrBucketPolicyNotFound - Check if error type is BucketPolicyNotFound.
func isErrBucketPolicyNotFound(err error) bool { func isErrBucketPolicyNotFound(err error) bool {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case PolicyNotFound: case PolicyNotFound:
return true return true
@ -420,7 +407,6 @@ func isErrBucketPolicyNotFound(err error) bool {
// isErrObjectNotFound - Check if error type is ObjectNotFound. // isErrObjectNotFound - Check if error type is ObjectNotFound.
func isErrObjectNotFound(err error) bool { func isErrObjectNotFound(err error) bool {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case ObjectNotFound: case ObjectNotFound:
return true return true

@ -20,7 +20,6 @@ import (
"context" "context"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/skyrings/skyring-common/tools/uuid" "github.com/skyrings/skyring-common/tools/uuid"
) )
@ -214,7 +213,7 @@ func checkPutObjectArgs(ctx context.Context, bucket, object string, obj ObjectLa
func checkBucketExist(ctx context.Context, bucket string, obj ObjectLayer) error { func checkBucketExist(ctx context.Context, bucket string, obj ObjectLayer) error {
_, err := obj.GetBucketInfo(ctx, bucket) _, err := obj.GetBucketInfo(ctx, bucket)
if err != nil { if err != nil {
return errors.Cause(err) return err
} }
return nil return nil
} }

@ -25,7 +25,6 @@ import (
"testing" "testing"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -124,7 +123,7 @@ func testObjectAbortMultipartUpload(obj ObjectLayer, instanceType string, t Test
if testCase.expectedErrType == nil && err != nil { if testCase.expectedErrType == nil && err != nil {
t.Errorf("Test %d, unexpected err is received: %v, expected:%v\n", i+1, err, testCase.expectedErrType) t.Errorf("Test %d, unexpected err is received: %v, expected:%v\n", i+1, err, testCase.expectedErrType)
} }
if testCase.expectedErrType != nil && !isSameType(errors.Cause(err), testCase.expectedErrType) { if testCase.expectedErrType != nil && !isSameType(err, testCase.expectedErrType) {
t.Errorf("Test %d, unexpected err is received: %v, expected:%v\n", i+1, err, testCase.expectedErrType) t.Errorf("Test %d, unexpected err is received: %v, expected:%v\n", i+1, err, testCase.expectedErrType)
} }
} }
@ -153,7 +152,6 @@ func testObjectAPIIsUploadIDExists(obj ObjectLayer, instanceType string, t TestE
} }
err = obj.AbortMultipartUpload(context.Background(), bucket, object, "abc") err = obj.AbortMultipartUpload(context.Background(), bucket, object, "abc")
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case InvalidUploadID: case InvalidUploadID:
default: default:

@ -27,7 +27,6 @@ import (
"testing" "testing"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -164,7 +163,6 @@ func testObjectAPIPutObject(obj ObjectLayer, instanceType string, t TestErrHandl
for i, testCase := range testCases { for i, testCase := range testCases {
objInfo, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], testCase.inputSHA256), testCase.inputMeta) objInfo, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], testCase.inputSHA256), testCase.inputMeta)
actualErr = errors.Cause(actualErr)
if actualErr != nil && testCase.expectedError == nil { if actualErr != nil && testCase.expectedError == nil {
t.Errorf("Test %d: %s: Expected to pass, but failed with: error %s.", i+1, instanceType, actualErr.Error()) t.Errorf("Test %d: %s: Expected to pass, but failed with: error %s.", i+1, instanceType, actualErr.Error())
} }
@ -238,7 +236,6 @@ func testObjectAPIPutObjectDiskNotFound(obj ObjectLayer, instanceType string, di
sha256sum := "" sha256sum := ""
for i, testCase := range testCases { for i, testCase := range testCases {
objInfo, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], sha256sum), testCase.inputMeta) objInfo, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], sha256sum), testCase.inputMeta)
actualErr = errors.Cause(actualErr)
if actualErr != nil && testCase.shouldPass { if actualErr != nil && testCase.shouldPass {
t.Errorf("Test %d: %s: Expected to pass, but failed with: <ERROR> %s.", i+1, instanceType, actualErr.Error()) t.Errorf("Test %d: %s: Expected to pass, but failed with: <ERROR> %s.", i+1, instanceType, actualErr.Error())
} }
@ -288,7 +285,6 @@ func testObjectAPIPutObjectDiskNotFound(obj ObjectLayer, instanceType string, di
} }
_, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], sha256sum), testCase.inputMeta) _, actualErr := obj.PutObject(context.Background(), testCase.bucketName, testCase.objName, mustGetHashReader(t, bytes.NewReader(testCase.inputData), testCase.intputDataSize, testCase.inputMeta["etag"], sha256sum), testCase.inputMeta)
actualErr = errors.Cause(actualErr)
if actualErr != nil && testCase.shouldPass { if actualErr != nil && testCase.shouldPass {
t.Errorf("Test %d: %s: Expected to pass, but failed with: <ERROR> %s.", len(testCases)+1, instanceType, actualErr.Error()) t.Errorf("Test %d: %s: Expected to pass, but failed with: <ERROR> %s.", len(testCases)+1, instanceType, actualErr.Error())
} }

@ -33,7 +33,6 @@ import (
mux "github.com/gorilla/mux" mux "github.com/gorilla/mux"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/handlers" "github.com/minio/minio/pkg/handlers"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
@ -1386,7 +1385,6 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
} }
objInfo, err := completeMultiPartUpload(ctx, bucket, object, uploadID, completeParts) objInfo, err := completeMultiPartUpload(ctx, bucket, object, uploadID, completeParts)
if err != nil { if err != nil {
err = errors.Cause(err)
switch oErr := err.(type) { switch oErr := err.(type) {
case PartTooSmall: case PartTooSmall:
// Write part too small error. // Write part too small error.

@ -25,7 +25,6 @@ import (
"testing" "testing"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
) )
// Return pointer to testOneByteReadEOF{} // Return pointer to testOneByteReadEOF{}
@ -755,11 +754,8 @@ func testGetDirectoryReturnsObjectNotFound(obj ObjectLayer, instanceType string,
for i, testCase := range testCases { for i, testCase := range testCases {
_, expectedErr := obj.GetObjectInfo(context.Background(), bucketName, testCase.dir) _, expectedErr := obj.GetObjectInfo(context.Background(), bucketName, testCase.dir)
if expectedErr != nil { if expectedErr != nil && expectedErr.Error() != testCase.err.Error() {
expectedErr = errors.Cause(expectedErr) t.Errorf("Test %d, %s: Expected error %s, got %s", i+1, instanceType, testCase.err, expectedErr)
if expectedErr.Error() != testCase.err.Error() {
t.Errorf("Test %d, %s: Expected error %s, got %s", i+1, instanceType, testCase.err, expectedErr)
}
} }
} }
} }

@ -19,8 +19,6 @@ package cmd
import ( import (
"os" "os"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
// Tests - mkdirAll() // Tests - mkdirAll()
@ -32,11 +30,11 @@ func TestOSMkdirAll(t *testing.T) {
} }
defer os.RemoveAll(path) defer os.RemoveAll(path)
if err = mkdirAll("", 0777); errors.Cause(err) != errInvalidArgument { if err = mkdirAll("", 0777); err != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if err = mkdirAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), 0777); errors.Cause(err) != errFileNameTooLong { if err = mkdirAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), 0777); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -66,13 +64,13 @@ func TestOSRenameAll(t *testing.T) {
if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil { if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); errors.Cause(err) != errFileNotFound { if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "testvolume2")); err != errFileNotFound {
t.Fatal(err) t.Fatal(err)
} }
if err = renameAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); errors.Cause(err) != errFileNameTooLong { if err = renameAll(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"), pathJoin(path, "testvolume2")); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); errors.Cause(err) != errFileNameTooLong { if err = renameAll(pathJoin(path, "testvolume1"), pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
} }

@ -24,7 +24,6 @@ import (
"github.com/minio/mc/pkg/console" "github.com/minio/mc/pkg/console"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
) )
var printEndpointError = func() func(Endpoint, error) { var printEndpointError = func() func(Endpoint, error) {
@ -142,7 +141,7 @@ func connectLoadInitFormats(firstDisk bool, endpoints EndpointList, setCount, dr
} }
for i, sErr := range sErrs { for i, sErr := range sErrs {
if _, ok := formatCriticalErrors[errors.Cause(sErr)]; ok { if _, ok := formatCriticalErrors[sErr]; ok {
return nil, fmt.Errorf("Disk %s: %s", endpoints[i], sErr) return nil, fmt.Errorf("Disk %s: %s", endpoints[i], sErr)
} }
} }

@ -21,7 +21,6 @@ import (
"testing" "testing"
"github.com/minio/minio/pkg/disk" "github.com/minio/minio/pkg/disk"
"github.com/minio/minio/pkg/errors"
) )
type testStorageRPCServer struct { type testStorageRPCServer struct {
@ -68,9 +67,8 @@ func createTestStorageServer(t *testing.T) *testStorageRPCServer {
} }
func errorIfInvalidToken(t *testing.T, err error) { func errorIfInvalidToken(t *testing.T, err error) {
realErr := errors.Cause(err) if err != errInvalidToken {
if realErr != errInvalidToken { t.Errorf("Expected to fail with %s but failed with %s", errInvalidToken, err)
t.Errorf("Expected to fail with %s but failed with %s", errInvalidToken, realErr)
} }
} }

@ -41,6 +41,21 @@ import (
"github.com/pkg/profile" "github.com/pkg/profile"
) )
// IsErrIgnored returns whether given error is ignored or not.
func IsErrIgnored(err error, ignoredErrs ...error) bool {
return IsErr(err, ignoredErrs...)
}
// IsErr returns whether given error is exact error.
func IsErr(err error, errs ...error) bool {
for _, exactErr := range errs {
if err == exactErr {
return true
}
}
return false
}
// Close Http tracing file. // Close Http tracing file.
func stopHTTPTrace() { func stopHTTPTrace() {
if globalHTTPTraceFile != nil { if globalHTTPTraceFile != nil {

@ -20,6 +20,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
@ -428,3 +429,26 @@ func TestCeilFrac(t *testing.T) {
} }
} }
} }
// Test if isErrIgnored works correctly.
func TestIsErrIgnored(t *testing.T) {
var errIgnored = fmt.Errorf("ignored error")
var testCases = []struct {
err error
ignored bool
}{
{
err: nil,
ignored: false,
},
{
err: errIgnored,
ignored: true,
},
}
for i, testCase := range testCases {
if ok := IsErrIgnored(testCase.err, errIgnored); ok != testCase.ignored {
t.Errorf("Test: %d, Expected %t, got %t", i+1, testCase.ignored, ok)
}
}
}

@ -37,7 +37,6 @@ import (
"github.com/minio/minio/browser" "github.com/minio/minio/browser"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/event" "github.com/minio/minio/pkg/event"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
) )
@ -759,7 +758,7 @@ func (web *webAPIHandlers) GetBucketPolicy(r *http.Request, args *GetBucketPolic
var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName) var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName)
if err != nil { if err != nil {
_, ok := errors.Cause(err).(BucketPolicyNotFound) _, ok := err.(BucketPolicyNotFound)
if !ok { if !ok {
return toJSONError(err, args.BucketName) return toJSONError(err, args.BucketName)
} }
@ -801,7 +800,7 @@ func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllB
} }
var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName) var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName)
if err != nil { if err != nil {
_, ok := errors.Cause(err).(PolicyNotFound) _, ok := err.(PolicyNotFound)
if !ok { if !ok {
return toJSONError(err, args.BucketName) return toJSONError(err, args.BucketName)
} }
@ -848,7 +847,7 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName) var policyInfo, err = objectAPI.GetBucketPolicy(context.Background(), args.BucketName)
if err != nil { if err != nil {
if _, ok := errors.Cause(err).(PolicyNotFound); !ok { if _, ok := err.(PolicyNotFound); !ok {
return toJSONError(err, args.BucketName) return toJSONError(err, args.BucketName)
} }
policyInfo = policy.BucketAccessPolicy{Version: "2012-10-17"} policyInfo = policy.BucketAccessPolicy{Version: "2012-10-17"}
@ -1007,7 +1006,6 @@ func toJSONError(err error, params ...string) (jerr *json2.Error) {
// toWebAPIError - convert into error into APIError. // toWebAPIError - convert into error into APIError.
func toWebAPIError(err error) APIError { func toWebAPIError(err error) APIError {
err = errors.Cause(err)
if err == errAuthentication { if err == errAuthentication {
return APIError{ return APIError{
Code: "AccessDenied", Code: "AccessDenied",

@ -30,7 +30,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/bpool" "github.com/minio/minio/pkg/bpool"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
"github.com/minio/minio/pkg/sync/errgroup" "github.com/minio/minio/pkg/sync/errgroup"
@ -661,7 +660,7 @@ func listDirSetsFactory(ctx context.Context, isLeaf isLeafFunc, treeWalkIgnoredE
if err != nil { if err != nil {
// For any reason disk was deleted or goes offline, continue // For any reason disk was deleted or goes offline, continue
// and list from other disks if possible. // and list from other disks if possible.
if errors.IsErrIgnored(err, treeWalkIgnoredErrs...) { if IsErrIgnored(err, treeWalkIgnoredErrs...) {
continue continue
} }
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
@ -779,7 +778,7 @@ func (s *xlSets) ListObjects(ctx context.Context, bucket, prefix, marker, delimi
// Ignore errFileNotFound as the object might have got // Ignore errFileNotFound as the object might have got
// deleted in the interim period of listing and getObjectInfo(), // deleted in the interim period of listing and getObjectInfo(),
// ignore quorum error as it might be an entry from an outdated disk. // ignore quorum error as it might be an entry from an outdated disk.
switch errors.Cause(err) { switch err {
case errFileNotFound, errXLReadQuorum: case errFileNotFound, errXLReadQuorum:
continue continue
} }
@ -1407,7 +1406,7 @@ func (s *xlSets) listObjectsHeal(ctx context.Context, bucket, prefix, marker, de
} }
if err != nil { if err != nil {
// Ignore errFileNotFound // Ignore errFileNotFound
if errors.Cause(err) == errFileNotFound { if err == errFileNotFound {
continue continue
} }
return loi, toObjectErr(err, bucket, prefix) return loi, toObjectErr(err, bucket, prefix)

@ -24,7 +24,6 @@ import (
"github.com/minio/minio-go/pkg/policy" "github.com/minio/minio-go/pkg/policy"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
) )
// list all errors that can be ignore in a bucket operation. // list all errors that can be ignore in a bucket operation.
@ -75,7 +74,7 @@ func (xl xlObjects) MakeBucketWithLocation(ctx context.Context, bucket, location
writeQuorum := len(xl.getDisks())/2 + 1 writeQuorum := len(xl.getDisks())/2 + 1
err := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum) err := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
// Purge successfully created buckets if we don't have writeQuorum. // Purge successfully created buckets if we don't have writeQuorum.
undoMakeBucket(xl.getDisks(), bucket) undoMakeBucket(xl.getDisks(), bucket)
} }
@ -142,7 +141,7 @@ func (xl xlObjects) getBucketInfo(ctx context.Context, bucketName string) (bucke
logger.LogIf(ctx, serr) logger.LogIf(ctx, serr)
err = serr err = serr
// For any reason disk went offline continue and pick the next one. // For any reason disk went offline continue and pick the next one.
if errors.IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) { if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
bucketErrs = append(bucketErrs, err) bucketErrs = append(bucketErrs, err)
continue continue
} }
@ -208,7 +207,7 @@ func (xl xlObjects) listBuckets(ctx context.Context) (bucketsInfo []BucketInfo,
} }
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
// Ignore any disks not found. // Ignore any disks not found.
if errors.IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) { if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
continue continue
} }
break break
@ -268,7 +267,7 @@ func (xl xlObjects) DeleteBucket(ctx context.Context, bucket string) error {
err = cleanupDir(ctx, disk, minioMetaMultipartBucket, bucket) err = cleanupDir(ctx, disk, minioMetaMultipartBucket, bucket)
if err != nil { if err != nil {
if errors.Cause(err) == errVolumeNotFound { if err == errVolumeNotFound {
return return
} }
dErrs[index] = err dErrs[index] = err
@ -281,7 +280,7 @@ func (xl xlObjects) DeleteBucket(ctx context.Context, bucket string) error {
writeQuorum := len(xl.getDisks())/2 + 1 writeQuorum := len(xl.getDisks())/2 + 1
err := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum) err := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
xl.undoDeleteBucket(bucket) xl.undoDeleteBucket(bucket)
} }
if err != nil { if err != nil {

@ -21,7 +21,6 @@ import (
"path" "path"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
) )
// getLoadBalancedDisks - fetches load balanced (sufficiently randomized) disk slice. // getLoadBalancedDisks - fetches load balanced (sufficiently randomized) disk slice.
@ -65,7 +64,7 @@ func (xl xlObjects) isObject(bucket, prefix string) (ok bool) {
return true return true
} }
// Ignore for file not found, disk not found or faulty disk. // Ignore for file not found, disk not found or faulty disk.
if errors.IsErrIgnored(err, xlTreeWalkIgnoredErrs...) { if IsErrIgnored(err, xlTreeWalkIgnoredErrs...) {
continue continue
} }
reqInfo := &logger.ReqInfo{BucketName: bucket} reqInfo := &logger.ReqInfo{BucketName: bucket}

@ -23,12 +23,12 @@ import (
"sync" "sync"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
) )
func (xl xlObjects) ReloadFormat(ctx context.Context, dryRun bool) error { func (xl xlObjects) ReloadFormat(ctx context.Context, dryRun bool) error {
return errors.Trace(NotImplemented{}) logger.LogIf(ctx, NotImplemented{})
return NotImplemented{}
} }
func (xl xlObjects) HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error) { func (xl xlObjects) HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error) {
@ -120,13 +120,13 @@ func healBucket(ctx context.Context, storageDisks []StorageAPI, bucket string, w
go func(index int, disk StorageAPI) { go func(index int, disk StorageAPI) {
defer wg.Done() defer wg.Done()
if _, serr := disk.StatVol(bucket); serr != nil { if _, serr := disk.StatVol(bucket); serr != nil {
if errors.Cause(serr) == errDiskNotFound { if serr == errDiskNotFound {
beforeState[index] = madmin.DriveStateOffline beforeState[index] = madmin.DriveStateOffline
afterState[index] = madmin.DriveStateOffline afterState[index] = madmin.DriveStateOffline
dErrs[index] = serr dErrs[index] = serr
return return
} }
if errors.Cause(serr) != errVolumeNotFound { if serr != errVolumeNotFound {
beforeState[index] = madmin.DriveStateCorrupt beforeState[index] = madmin.DriveStateCorrupt
afterState[index] = madmin.DriveStateCorrupt afterState[index] = madmin.DriveStateCorrupt
dErrs[index] = serr dErrs[index] = serr
@ -190,7 +190,7 @@ func healBucket(ctx context.Context, storageDisks []StorageAPI, bucket string, w
} }
reducedErr := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum) reducedErr := reduceWriteQuorumErrs(ctx, dErrs, bucketOpIgnoredErrs, writeQuorum)
if errors.Cause(reducedErr) == errXLWriteQuorum { if reducedErr == errXLWriteQuorum {
// Purge successfully created buckets if we don't have writeQuorum. // Purge successfully created buckets if we don't have writeQuorum.
undoMakeBucket(storageDisks, bucket) undoMakeBucket(storageDisks, bucket)
} }
@ -256,7 +256,7 @@ func listAllBuckets(storageDisks []StorageAPI) (buckets map[string]VolInfo,
var volsInfo []VolInfo var volsInfo []VolInfo
volsInfo, err = disk.ListVols() volsInfo, err = disk.ListVols()
if err != nil { if err != nil {
if errors.IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) { if IsErrIgnored(err, bucketMetadataOpIgnoredErrs...) {
continue continue
} }
return nil, nil, err return nil, nil, err
@ -330,11 +330,11 @@ func healObject(ctx context.Context, storageDisks []StorageAPI, bucket string, o
result.ObjectSize = partsMetadata[i].Stat.Size result.ObjectSize = partsMetadata[i].Stat.Size
result.ParityBlocks = partsMetadata[i].Erasure.ParityBlocks result.ParityBlocks = partsMetadata[i].Erasure.ParityBlocks
result.DataBlocks = partsMetadata[i].Erasure.DataBlocks result.DataBlocks = partsMetadata[i].Erasure.DataBlocks
case errors.Cause(errs[i]) == errDiskNotFound: case errs[i] == errDiskNotFound:
driveState = madmin.DriveStateOffline driveState = madmin.DriveStateOffline
case errors.Cause(errs[i]) == errFileNotFound, errors.Cause(errs[i]) == errVolumeNotFound: case errs[i] == errFileNotFound, errs[i] == errVolumeNotFound:
fallthrough fallthrough
case errors.Cause(dataErrs[i]) == errFileNotFound, errors.Cause(dataErrs[i]) == errVolumeNotFound: case dataErrs[i] == errFileNotFound, dataErrs[i] == errVolumeNotFound:
driveState = madmin.DriveStateMissing driveState = madmin.DriveStateMissing
default: default:
// all remaining cases imply corrupt data/metadata // all remaining cases imply corrupt data/metadata
@ -412,8 +412,7 @@ func healObject(ctx context.Context, storageDisks []StorageAPI, bucket string, o
continue continue
} }
// List and delete the object directory, ignoring // List and delete the object directory,
// errors.
files, derr := disk.ListDir(bucket, object) files, derr := disk.ListDir(bucket, object)
if derr == nil { if derr == nil {
for _, entry := range files { for _, entry := range files {

@ -22,8 +22,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/minio/minio/pkg/errors"
) )
// Tests undoes and validates if the undoing completes successfully. // Tests undoes and validates if the undoing completes successfully.
@ -57,7 +55,6 @@ func TestUndoMakeBucket(t *testing.T) {
// Validate if bucket was deleted properly. // Validate if bucket was deleted properly.
_, err = obj.GetBucketInfo(context.Background(), bucketName) _, err = obj.GetBucketInfo(context.Background(), bucketName)
if err != nil { if err != nil {
err = errors.Cause(err)
switch err.(type) { switch err.(type) {
case BucketNotFound: case BucketNotFound:
default: default:
@ -147,7 +144,7 @@ func TestHealObjectXL(t *testing.T) {
// Try healing now, expect to receive errDiskNotFound. // Try healing now, expect to receive errDiskNotFound.
_, err = obj.HealObject(context.Background(), bucket, object, false) _, err = obj.HealObject(context.Background(), bucket, object, false)
// since majority of xl.jsons are not available, object quorum can't be read properly and error will be errXLReadQuorum // since majority of xl.jsons are not available, object quorum can't be read properly and error will be errXLReadQuorum
if errors.Cause(err) != errXLReadQuorum { if err != errXLReadQuorum {
t.Errorf("Expected %v but received %v", errDiskNotFound, err) t.Errorf("Expected %v but received %v", errDiskNotFound, err)
} }
} }

@ -19,8 +19,6 @@ package cmd
import ( import (
"context" "context"
"sort" "sort"
"github.com/minio/minio/pkg/errors"
) )
// Returns function "listDir" of the type listDirFunc. // Returns function "listDir" of the type listDirFunc.
@ -39,7 +37,7 @@ func listDirFactory(ctx context.Context, isLeaf isLeafFunc, treeWalkIgnoredErrs
if err != nil { if err != nil {
// For any reason disk was deleted or goes offline, continue // For any reason disk was deleted or goes offline, continue
// and list from other disks if possible. // and list from other disks if possible.
if errors.IsErrIgnored(err, treeWalkIgnoredErrs...) { if IsErrIgnored(err, treeWalkIgnoredErrs...) {
continue continue
} }
return nil, false, err return nil, false, err
@ -114,7 +112,7 @@ func (xl xlObjects) listObjects(ctx context.Context, bucket, prefix, marker, del
// Ignore errFileNotFound as the object might have got // Ignore errFileNotFound as the object might have got
// deleted in the interim period of listing and getObjectInfo(), // deleted in the interim period of listing and getObjectInfo(),
// ignore quorum error as it might be an entry from an outdated disk. // ignore quorum error as it might be an entry from an outdated disk.
switch errors.Cause(err) { switch err {
case errFileNotFound, errXLReadQuorum: case errFileNotFound, errXLReadQuorum:
continue continue
} }

@ -30,7 +30,6 @@ import (
"github.com/minio/highwayhash" "github.com/minio/highwayhash"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
sha256 "github.com/minio/sha256-simd" sha256 "github.com/minio/sha256-simd"
"golang.org/x/crypto/blake2b" "golang.org/x/crypto/blake2b"
) )
@ -416,7 +415,7 @@ func (xl xlObjects) readXLMetaParts(ctx context.Context, bucket, object string)
} }
// For any reason disk or bucket is not available continue // For any reason disk or bucket is not available continue
// and read from other disks. // and read from other disks.
if errors.IsErrIgnored(err, objMetadataOpIgnoredErrs...) { if IsErrIgnored(err, objMetadataOpIgnoredErrs...) {
ignoredErrs = append(ignoredErrs, err) ignoredErrs = append(ignoredErrs, err)
continue continue
} }
@ -444,7 +443,7 @@ func (xl xlObjects) readXLMetaStat(ctx context.Context, bucket, object string) (
} }
// For any reason disk or bucket is not available continue // For any reason disk or bucket is not available continue
// and read from other disks. // and read from other disks.
if errors.IsErrIgnored(err, objMetadataOpIgnoredErrs...) { if IsErrIgnored(err, objMetadataOpIgnoredErrs...) {
ignoredErrs = append(ignoredErrs, err) ignoredErrs = append(ignoredErrs, err)
continue continue
} }
@ -542,7 +541,7 @@ func writeUniqueXLMetadata(ctx context.Context, disks []StorageAPI, bucket, pref
wg.Wait() wg.Wait()
err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum) err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
// Delete all `xl.json` successfully renamed. // Delete all `xl.json` successfully renamed.
deleteAllXLMetadata(ctx, disks, bucket, prefix, mErrs) deleteAllXLMetadata(ctx, disks, bucket, prefix, mErrs)
} }
@ -581,7 +580,7 @@ func writeSameXLMetadata(ctx context.Context, disks []StorageAPI, bucket, prefix
wg.Wait() wg.Wait()
err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, writeQuorum) err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, writeQuorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
// Delete all `xl.json` successfully renamed. // Delete all `xl.json` successfully renamed.
deleteAllXLMetadata(ctx, disks, bucket, prefix, mErrs) deleteAllXLMetadata(ctx, disks, bucket, prefix, mErrs)
} }

@ -27,7 +27,6 @@ import (
"time" "time"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
errors2 "github.com/minio/minio/pkg/errors"
) )
// Tests for reading XL object info. // Tests for reading XL object info.
@ -95,7 +94,7 @@ func testXLReadStat(obj ObjectLayer, instanceType string, disks []string, t *tes
} }
_, _, err = obj.(*xlObjects).readXLMetaStat(context.Background(), bucketName, objectName) _, _, err = obj.(*xlObjects).readXLMetaStat(context.Background(), bucketName, objectName)
if errors2.Cause(err) != errVolumeNotFound { if err != errVolumeNotFound {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -180,7 +179,7 @@ func testXLReadMetaParts(obj ObjectLayer, instanceType string, disks []string, t
} }
_, _, err = obj.(*xlObjects).readXLMetaParts(context.Background(), minioMetaMultipartBucket, uploadIDPath) _, _, err = obj.(*xlObjects).readXLMetaParts(context.Background(), minioMetaMultipartBucket, uploadIDPath)
if errors2.Cause(err) != errFileNotFound { if err != errFileNotFound {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -299,7 +298,6 @@ func TestObjectToPartOffset(t *testing.T) {
// Test them. // Test them.
for _, testCase := range testCases { for _, testCase := range testCases {
index, offset, err := xlMeta.ObjectToPartOffset(context.Background(), testCase.offset) index, offset, err := xlMeta.ObjectToPartOffset(context.Background(), testCase.offset)
err = errors2.Cause(err)
if err != testCase.expectedErr { if err != testCase.expectedErr {
t.Fatalf("%+v: expected = %s, got: %s", testCase, testCase.expectedErr, err) t.Fatalf("%+v: expected = %s, got: %s", testCase, testCase.expectedErr, err)
} }
@ -357,7 +355,7 @@ func TestPickValidXLMeta(t *testing.T) {
for i, test := range testCases { for i, test := range testCases {
xlMeta, err := pickValidXLMeta(context.Background(), test.metaArr, test.modTime) xlMeta, err := pickValidXLMeta(context.Background(), test.metaArr, test.modTime)
if test.expectedErr != nil { if test.expectedErr != nil {
if errors2.Cause(err).Error() != test.expectedErr.Error() { if err.Error() != test.expectedErr.Error() {
t.Errorf("Test %d: Expected to fail with %v but received %v", t.Errorf("Test %d: Expected to fail with %v but received %v",
i+1, test.expectedErr, err) i+1, test.expectedErr, err)
} }

@ -27,7 +27,6 @@ import (
"time" "time"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
"github.com/minio/minio/pkg/mimedb" "github.com/minio/minio/pkg/mimedb"
) )
@ -79,7 +78,7 @@ func (xl xlObjects) statPart(ctx context.Context, bucket, object, uploadID, part
return fileInfo, nil return fileInfo, nil
} }
// For any reason disk was deleted or goes offline we continue to next disk. // For any reason disk was deleted or goes offline we continue to next disk.
if errors.IsErrIgnored(err, objMetadataOpIgnoredErrs...) { if IsErrIgnored(err, objMetadataOpIgnoredErrs...) {
ignoredErrs = append(ignoredErrs, err) ignoredErrs = append(ignoredErrs, err)
continue continue
} }
@ -129,7 +128,7 @@ func commitXLMetadata(ctx context.Context, disks []StorageAPI, srcBucket, srcPre
wg.Wait() wg.Wait()
err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum) err := reduceWriteQuorumErrs(ctx, mErrs, objectOpIgnoredErrs, quorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
// Delete all `xl.json` successfully renamed. // Delete all `xl.json` successfully renamed.
deleteAllXLMetadata(ctx, disks, dstBucket, dstPrefix, mErrs) deleteAllXLMetadata(ctx, disks, dstBucket, dstPrefix, mErrs)
} }
@ -337,7 +336,7 @@ func (xl xlObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID
} }
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum) reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
if errors.Cause(reducedErr) == errXLWriteQuorum { if reducedErr == errXLWriteQuorum {
preUploadIDLock.RUnlock() preUploadIDLock.RUnlock()
return pi, toObjectErr(reducedErr, bucket, object) return pi, toObjectErr(reducedErr, bucket, object)
} }
@ -413,7 +412,7 @@ func (xl xlObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID
// Read metadata again because it might be updated with parallel upload of another part. // Read metadata again because it might be updated with parallel upload of another part.
partsMetadata, errs = readAllXLMetadata(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath) partsMetadata, errs = readAllXLMetadata(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath)
reducedErr = reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum) reducedErr = reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
if errors.Cause(reducedErr) == errXLWriteQuorum { if reducedErr == errXLWriteQuorum {
return pi, toObjectErr(reducedErr, bucket, object) return pi, toObjectErr(reducedErr, bucket, object)
} }
@ -610,7 +609,7 @@ func (xl xlObjects) CompleteMultipartUpload(ctx context.Context, bucket string,
} }
reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum) reducedErr := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
if errors.Cause(reducedErr) == errXLWriteQuorum { if reducedErr == errXLWriteQuorum {
return oi, toObjectErr(reducedErr, bucket, object) return oi, toObjectErr(reducedErr, bucket, object)
} }

@ -21,8 +21,6 @@ import (
"os" "os"
"testing" "testing"
"time" "time"
"github.com/minio/minio/pkg/errors"
) )
// Tests cleanup multipart uploads for erasure coded backend. // Tests cleanup multipart uploads for erasure coded backend.
@ -68,7 +66,6 @@ func TestXLCleanupStaleMultipartUploads(t *testing.T) {
// Check if upload id was already purged. // Check if upload id was already purged.
if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil { if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil {
err = errors.Cause(err)
if _, ok := err.(InvalidUploadID); !ok { if _, ok := err.(InvalidUploadID); !ok {
t.Fatal("Unexpected err: ", err) t.Fatal("Unexpected err: ", err)
} }

@ -26,7 +26,6 @@ import (
"sync" "sync"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/errors"
"github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/hash"
"github.com/minio/minio/pkg/mimedb" "github.com/minio/minio/pkg/mimedb"
) )
@ -468,7 +467,7 @@ func rename(ctx context.Context, disks []StorageAPI, srcBucket, srcEntry, dstBuc
// We can safely allow RenameFile errors up to len(xl.getDisks()) - writeQuorum // We can safely allow RenameFile errors up to len(xl.getDisks()) - writeQuorum
// otherwise return failure. Cleanup successful renames. // otherwise return failure. Cleanup successful renames.
err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum) err := reduceWriteQuorumErrs(ctx, errs, objectOpIgnoredErrs, writeQuorum)
if errors.Cause(err) == errXLWriteQuorum { if err == errXLWriteQuorum {
// Undo all the partial rename operations. // Undo all the partial rename operations.
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isDir, errs) undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isDir, errs)
} }
@ -783,7 +782,7 @@ func (xl xlObjects) deleteObject(ctx context.Context, bucket, object string) err
} else { } else {
e = cleanupDir(ctx, disk, bucket, object) e = cleanupDir(ctx, disk, bucket, object)
} }
if e != nil && errors.Cause(e) != errVolumeNotFound { if e != nil && e != errVolumeNotFound {
dErrs[index] = e dErrs[index] = e
} }
}(index, disk, isDir) }(index, disk, isDir)

@ -28,7 +28,6 @@ import (
"time" "time"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
) )
func TestRepeatPutObjectPart(t *testing.T) { func TestRepeatPutObjectPart(t *testing.T) {
@ -98,7 +97,6 @@ func TestXLDeleteObjectBasic(t *testing.T) {
} }
for i, test := range testCases { for i, test := range testCases {
actualErr := xl.DeleteObject(context.Background(), test.bucket, test.object) actualErr := xl.DeleteObject(context.Background(), test.bucket, test.object)
actualErr = errors.Cause(actualErr)
if test.expectedErr != nil && actualErr != test.expectedErr { if test.expectedErr != nil && actualErr != test.expectedErr {
t.Errorf("Test %d: Expected to fail with %s, but failed with %s", i+1, test.expectedErr, actualErr) t.Errorf("Test %d: Expected to fail with %s, but failed with %s", i+1, test.expectedErr, actualErr)
} }
@ -154,7 +152,6 @@ func TestXLDeleteObjectDiskNotFound(t *testing.T) {
xl.storageDisks[7] = nil xl.storageDisks[7] = nil
xl.storageDisks[8] = nil xl.storageDisks[8] = nil
err = obj.DeleteObject(context.Background(), bucket, object) err = obj.DeleteObject(context.Background(), bucket, object)
err = errors.Cause(err)
// since majority of disks are not available, metaquorum is not achieved and hence errXLReadQuorum error // since majority of disks are not available, metaquorum is not achieved and hence errXLReadQuorum error
if err != toObjectErr(errXLReadQuorum, bucket, object) { if err != toObjectErr(errXLReadQuorum, bucket, object) {
t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errXLReadQuorum, bucket, object), err) t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errXLReadQuorum, bucket, object), err)
@ -205,7 +202,6 @@ func TestGetObjectNoQuorum(t *testing.T) {
} }
// Fetch object from store. // Fetch object from store.
err = xl.GetObject(context.Background(), bucket, object, 0, int64(len("abcd")), ioutil.Discard, "") err = xl.GetObject(context.Background(), bucket, object, 0, int64(len("abcd")), ioutil.Discard, "")
err = errors.Cause(err)
if err != toObjectErr(errXLReadQuorum, bucket, object) { if err != toObjectErr(errXLReadQuorum, bucket, object) {
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err) t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
} }
@ -256,7 +252,6 @@ func TestPutObjectNoQuorum(t *testing.T) {
} }
// Upload new content to same object "object" // Upload new content to same object "object"
_, err = obj.PutObject(context.Background(), bucket, object, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil) _, err = obj.PutObject(context.Background(), bucket, object, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
err = errors.Cause(err)
if err != toObjectErr(errXLWriteQuorum, bucket, object) { if err != toObjectErr(errXLWriteQuorum, bucket, object) {
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err) t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
} }

@ -26,7 +26,6 @@ import (
"time" "time"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
errors2 "github.com/minio/minio/pkg/errors"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
@ -39,7 +38,7 @@ import (
func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error) { func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error) {
errorCounts := make(map[error]int) errorCounts := make(map[error]int)
for _, err := range errs { for _, err := range errs {
if errors2.IsErrIgnored(err, ignoredErrs...) { if IsErrIgnored(err, ignoredErrs...) {
continue continue
} }
errorCounts[err]++ errorCounts[err]++

@ -26,7 +26,6 @@ import (
"testing" "testing"
humanize "github.com/dustin/go-humanize" humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/errors"
) )
// Tests caclculating disk count. // Tests caclculating disk count.
@ -93,11 +92,11 @@ func TestReduceErrs(t *testing.T) {
// Validates list of all the testcases for returning valid errors. // Validates list of all the testcases for returning valid errors.
for i, testCase := range testCases { for i, testCase := range testCases {
gotErr := reduceReadQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 5) gotErr := reduceReadQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 5)
if errors.Cause(gotErr) != testCase.err { if gotErr != testCase.err {
t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr) t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr)
} }
gotNewErr := reduceWriteQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 6) gotNewErr := reduceWriteQuorumErrs(context.Background(), testCase.errs, testCase.ignoredErrs, 6)
if errors.Cause(gotNewErr) != errXLWriteQuorum { if gotNewErr != errXLWriteQuorum {
t.Errorf("Test %d : expected %s, got %s", i+1, errXLWriteQuorum, gotErr) t.Errorf("Test %d : expected %s, got %s", i+1, errXLWriteQuorum, gotErr)
} }
} }
@ -388,8 +387,8 @@ func TestGetPartSizeFromIdx(t *testing.T) {
if err == nil { if err == nil {
t.Errorf("Test %d: Expected to failed but passed. %s", i+1, err) t.Errorf("Test %d: Expected to failed but passed. %s", i+1, err)
} }
if err != nil && errors.Cause(err) != testCaseFailure.err { if err != nil && err != testCaseFailure.err {
t.Errorf("Test %d: Expected err %s, but got %s", i+1, testCaseFailure.err, errors.Cause(err)) t.Errorf("Test %d: Expected err %s, but got %s", i+1, testCaseFailure.err, err)
} }
} }
} }

@ -24,7 +24,6 @@ import (
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/bpool" "github.com/minio/minio/pkg/bpool"
"github.com/minio/minio/pkg/disk" "github.com/minio/minio/pkg/disk"
"github.com/minio/minio/pkg/errors"
) )
// XL constants. // XL constants.
@ -142,7 +141,7 @@ func getDisksInfo(disks []StorageAPI) (disksInfo []disk.Info, onlineDisks int, o
info, err := storageDisk.DiskInfo() info, err := storageDisk.DiskInfo()
if err != nil { if err != nil {
logger.LogIf(context.Background(), err) logger.LogIf(context.Background(), err)
if errors.IsErr(err, baseErrs...) { if IsErr(err, baseErrs...) {
offlineDisks++ offlineDisks++
continue continue
} }

@ -1,154 +0,0 @@
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package errors
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
)
var (
// Package path of the project.
pkgPath string
)
// Init - initialize package path.
func Init(gopath string, p string) {
pkgPath = filepath.Join(gopath, "src", p) + string(os.PathSeparator)
}
// stackInfo - Represents a stack frame in the stack trace.
type stackInfo struct {
Filename string `json:"fileName"` // File where error occurred
Line int `json:"line"` // Line where error occurred
Name string `json:"name"` // Name of the function where error occurred
}
// Error - error type containing cause and the stack trace.
type Error struct {
Cause error // Holds the cause error
stack []stackInfo // Stack trace info.
errs []error // Useful for XL to hold errors from all disks
}
// Implement error interface.
func (e Error) Error() string {
return e.Cause.Error()
}
// Stack - returns slice of stack trace.
func (e Error) Stack() []string {
var stack []string
for _, info := range e.stack {
stack = append(stack, fmt.Sprintf("%s:%d:%s()", info.Filename, info.Line, info.Name))
}
return stack
}
// Trace - return new Error type.
func Trace(e error, errs ...error) error {
// Error is nil nothing to do return nil.
if e == nil {
return nil
}
// Already a trace error should be returned as is.
if _, ok := e.(*Error); ok {
return e
}
err := &Error{}
err.Cause = e
err.errs = errs
stack := make([]uintptr, 40)
length := runtime.Callers(2, stack)
if length > len(stack) {
length = len(stack)
}
stack = stack[:length]
for _, pc := range stack {
pc = pc - 1
fn := runtime.FuncForPC(pc)
file, line := fn.FileLine(pc)
var suffixFound bool
for _, ignoreName := range []string{
"runtime.",
"testing.",
} {
if strings.HasPrefix(fn.Name(), ignoreName) {
suffixFound = true
break
}
}
if suffixFound {
continue
}
_, name := filepath.Split(fn.Name())
name = strings.SplitN(name, ".", 2)[1]
file = filepath.FromSlash(strings.TrimPrefix(filepath.ToSlash(file), filepath.ToSlash(pkgPath)))
err.stack = append(err.stack, stackInfo{
Filename: file,
Line: line,
Name: name,
})
}
return err
}
// Cause - Returns the underlying cause error.
func Cause(err error) error {
if e, ok := err.(*Error); ok {
err = e.Cause
}
return err
}
// Causes - Returns slice of underlying cause error.
func Causes(errs []error) (cerrs []error) {
for _, err := range errs {
cerrs = append(cerrs, Cause(err))
}
return cerrs
}
// IsErrIgnored returns whether given error is ignored or not.
func IsErrIgnored(err error, ignoredErrs ...error) bool {
return IsErr(err, ignoredErrs...)
}
// IsErr returns whether given error is exact error.
func IsErr(err error, errs ...error) bool {
err = Cause(err)
for _, exactErr := range errs {
if err == exactErr {
return true
}
}
return false
}
// Tracef behaves like fmt.Errorf but adds traces to the returned error.
func Tracef(format string, args ...interface{}) error {
return Trace(fmt.Errorf(format, args...))
}

@ -1,120 +0,0 @@
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package errors
import (
"fmt"
"go/build"
"path/filepath"
"reflect"
"strings"
"testing"
)
// Test trace errors.
func TestTrace(t *testing.T) {
var errExpectedCause = fmt.Errorf("traceable error")
var testCases = []struct {
expectedCauseErr error
}{
{
expectedCauseErr: nil,
},
{
expectedCauseErr: errExpectedCause,
},
{
expectedCauseErr: Trace(errExpectedCause),
},
}
for i, testCase := range testCases {
if err := Trace(testCase.expectedCauseErr); err != nil {
if errGotCause := Cause(err); errGotCause != Cause(testCase.expectedCauseErr) {
t.Errorf("Test: %d Expected %s, got %s", i+1, testCase.expectedCauseErr, errGotCause)
}
}
}
}
// Test if isErrIgnored works correctly.
func TestIsErrIgnored(t *testing.T) {
var errIgnored = fmt.Errorf("ignored error")
var testCases = []struct {
err error
ignored bool
}{
{
err: nil,
ignored: false,
},
{
err: errIgnored,
ignored: true,
},
{
err: Trace(errIgnored),
ignored: true,
},
}
for i, testCase := range testCases {
if ok := IsErrIgnored(testCase.err, errIgnored); ok != testCase.ignored {
t.Errorf("Test: %d, Expected %t, got %t", i+1, testCase.ignored, ok)
}
}
}
// Tests if pkgPath is set properly in init.
func TestInit(t *testing.T) {
Init("/home/test/go", "test")
if filepath.ToSlash(pkgPath) != "/home/test/go/src/test/" {
t.Fatalf("Expected pkgPath to be \"/home/test/go/src/test/\", found %s", pkgPath)
}
}
// Tests stack output.
func TestStack(t *testing.T) {
Init(build.Default.GOPATH, "github.com/minio/minio")
err := Trace(fmt.Errorf("traceable error"))
if terr, ok := err.(*Error); ok {
if !strings.HasSuffix(terr.Stack()[0], "TestStack()") {
t.Errorf("Expected suffix \"TestStack()\", got %s", terr.Stack()[0])
}
}
// Test if the cause error is returned properly with the underlying string.
if err.Error() != "traceable error" {
t.Errorf("Expected \"traceable error\", got %s", err.Error())
}
}
// Tests converting error causes.
func TestErrCauses(t *testing.T) {
errTraceableError := fmt.Errorf("traceable error")
var errs = []error{
errTraceableError,
errTraceableError,
errTraceableError,
}
var terrs []error
for _, err := range errs {
terrs = append(terrs, Trace(err))
}
cerrs := Causes(terrs)
if !reflect.DeepEqual(errs, cerrs) {
t.Errorf("Expected %#v, got %#v", errs, cerrs)
}
}
Loading…
Cancel
Save