storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/storage-errors.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2015-2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import "errors"
    20  
    21  // errUnexpected - unexpected error, requires manual intervention.
    22  var errUnexpected = StorageErr("unexpected error, please report this issue at https://github.com/minio/minio/issues")
    23  
    24  // errCorruptedFormat - corrupted backend format.
    25  var errCorruptedFormat = StorageErr("corrupted backend format, specified disk mount has unexpected previous content")
    26  
    27  // errUnformattedDisk - unformatted disk found.
    28  var errUnformattedDisk = StorageErr("unformatted disk found")
    29  
    30  // errInconsistentDisk - inconsistent disk found.
    31  var errInconsistentDisk = StorageErr("inconsistent disk found")
    32  
    33  // errUnsupporteDisk - when disk does not support O_DIRECT flag.
    34  var errUnsupportedDisk = StorageErr("disk does not support O_DIRECT")
    35  
    36  // errDiskFull - cannot create volume or files when disk is full.
    37  var errDiskFull = StorageErr("disk path full")
    38  
    39  // errDiskNotDir - cannot use storage disk if its not a directory
    40  var errDiskNotDir = StorageErr("disk is not directory or mountpoint")
    41  
    42  // errDiskNotFound - cannot find the underlying configured disk anymore.
    43  var errDiskNotFound = StorageErr("disk not found")
    44  
    45  // errFaultyRemoteDisk - remote disk is faulty.
    46  var errFaultyRemoteDisk = StorageErr("remote disk is faulty")
    47  
    48  // errFaultyDisk - disk is faulty.
    49  var errFaultyDisk = StorageErr("disk is faulty")
    50  
    51  // errDiskAccessDenied - we don't have write permissions on disk.
    52  var errDiskAccessDenied = StorageErr("disk access denied")
    53  
    54  // errFileNotFound - cannot find the file.
    55  var errFileNotFound = StorageErr("file not found")
    56  
    57  // errFileNotFound - cannot find requested file version.
    58  var errFileVersionNotFound = StorageErr("file version not found")
    59  
    60  // errTooManyOpenFiles - too many open files.
    61  var errTooManyOpenFiles = StorageErr("too many open files, please increase 'ulimit -n'")
    62  
    63  // errFileNameTooLong - given file name is too long than supported length.
    64  var errFileNameTooLong = StorageErr("file name too long")
    65  
    66  // errVolumeExists - cannot create same volume again.
    67  var errVolumeExists = StorageErr("volume already exists")
    68  
    69  // errIsNotRegular - not of regular file type.
    70  var errIsNotRegular = StorageErr("not of regular file type")
    71  
    72  // errPathNotFound - cannot find the path.
    73  var errPathNotFound = StorageErr("path not found")
    74  
    75  // errVolumeNotFound - cannot find the volume.
    76  var errVolumeNotFound = StorageErr("volume not found")
    77  
    78  // errVolumeNotEmpty - volume not empty.
    79  var errVolumeNotEmpty = StorageErr("volume is not empty")
    80  
    81  // errVolumeAccessDenied - cannot access volume, insufficient permissions.
    82  var errVolumeAccessDenied = StorageErr("volume access denied")
    83  
    84  // errFileAccessDenied - cannot access file, insufficient permissions.
    85  var errFileAccessDenied = StorageErr("file access denied")
    86  
    87  // errFileCorrupt - file has an unexpected size, or is not readable
    88  var errFileCorrupt = StorageErr("file is corrupted")
    89  
    90  // errFileParentIsFile - cannot have overlapping objects, parent is already a file.
    91  var errFileParentIsFile = StorageErr("parent is a file")
    92  
    93  // errBitrotHashAlgoInvalid - the algo for bit-rot hash
    94  // verification is empty or invalid.
    95  var errBitrotHashAlgoInvalid = StorageErr("bit-rot hash algorithm is invalid")
    96  
    97  // errCrossDeviceLink - rename across devices not allowed.
    98  var errCrossDeviceLink = StorageErr("Rename across devices not allowed, please fix your backend configuration")
    99  
   100  // errMinDiskSize - cannot create volume or files when disk size is less than threshold.
   101  var errMinDiskSize = StorageErr("The disk size is less than 900MiB threshold")
   102  
   103  // errLessData - returned when less data available than what was requested.
   104  var errLessData = StorageErr("less data available than what was requested")
   105  
   106  // errMoreData = returned when more data was sent by the caller than what it was supposed to.
   107  var errMoreData = StorageErr("more data was sent than what was advertised")
   108  
   109  // indicates readDirFn to return without further applying the fn()
   110  var errDoneForNow = errors.New("done for now")
   111  
   112  // errSkipFile returned by the fn() for readDirFn() when it needs
   113  // to proceed to next entry.
   114  var errSkipFile = errors.New("skip this file")
   115  
   116  // StorageErr represents error generated by xlStorage call.
   117  type StorageErr string
   118  
   119  func (h StorageErr) Error() string {
   120  	return string(h)
   121  }
   122  
   123  // Collection of basic errors.
   124  var baseErrs = []error{
   125  	errDiskNotFound,
   126  	errFaultyDisk,
   127  	errFaultyRemoteDisk,
   128  }
   129  
   130  var baseIgnoredErrs = baseErrs
   131  
   132  // Is a one place function which converts all os.PathError
   133  // into a more FS object layer friendly form, converts
   134  // known errors into their typed form for top level
   135  // interpretation.
   136  func osErrToFileErr(err error) error {
   137  	if err == nil {
   138  		return nil
   139  	}
   140  	if osIsNotExist(err) {
   141  		return errFileNotFound
   142  	}
   143  	if osIsPermission(err) {
   144  		return errFileAccessDenied
   145  	}
   146  	if isSysErrNotDir(err) || isSysErrIsDir(err) {
   147  		return errFileNotFound
   148  	}
   149  	if isSysErrPathNotFound(err) {
   150  		return errFileNotFound
   151  	}
   152  	if isSysErrTooManyFiles(err) {
   153  		return errTooManyOpenFiles
   154  	}
   155  	if isSysErrHandleInvalid(err) {
   156  		return errFileNotFound
   157  	}
   158  	if isSysErrIO(err) {
   159  		return errFaultyDisk
   160  	}
   161  	if isSysErrInvalidArg(err) {
   162  		return errUnsupportedDisk
   163  	}
   164  	if isSysErrNoSpace(err) {
   165  		return errDiskFull
   166  	}
   167  	return err
   168  }