s3: Handle QuotaExceeded errors

Add a new storagedriver error to be used when quotas are exceeded, and return it
from the S3 driver.

Signed-off-by: Adam Wolfe Gordon <awg@digitalocean.com>
This commit is contained in:
Adam Wolfe Gordon 2020-10-23 14:25:49 -06:00
parent f2331f9d03
commit d192a974fb
3 changed files with 20 additions and 2 deletions

View File

@ -80,6 +80,9 @@ func (base *Base) setDriverName(e error) error {
case storagedriver.InvalidOffsetError:
actual.DriverName = base.StorageDriver.Name()
return actual
case storagedriver.QuotaExceededError:
actual.DriverName = base.StorageDriver.Name()
return actual
default:
storageError := storagedriver.Error{
DriverName: base.StorageDriver.Name(),

View File

@ -1188,8 +1188,13 @@ func (d *Driver) S3BucketKey(path string) string {
}
func parseError(path string, err error) error {
if s3Err, ok := err.(awserr.Error); ok && s3Err.Code() == "NoSuchKey" {
if s3Err, ok := err.(awserr.Error); ok {
switch s3Err.Code() {
case "NoSuchKey":
return storagedriver.PathNotFoundError{Path: path}
case "QuotaExceeded":
return storagedriver.QuotaExceededError{}
}
}
return err

View File

@ -159,6 +159,16 @@ func (err InvalidOffsetError) Error() string {
return fmt.Sprintf("%s: invalid offset: %d for path: %s", err.DriverName, err.Offset, err.Path)
}
// QuotaExceededError is returned when a storage quota is exceeded during a
// write.
type QuotaExceededError struct {
DriverName string
}
func (err QuotaExceededError) Error() string {
return fmt.Sprintf("%s: quota exceeded", err.DriverName)
}
// Error is a catch-all error type which captures an error string and
// the driver type on which it occurred.
type Error struct {