mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
@@ -23,13 +23,14 @@ import (
|
||||
// Error is the generic type for any error happening during tag
|
||||
// parsing.
|
||||
type Error struct {
|
||||
err error
|
||||
err error
|
||||
code string
|
||||
}
|
||||
|
||||
// Errorf - formats according to a format specifier and returns
|
||||
// the string as a value that satisfies error of type tagging.Error
|
||||
func Errorf(format string, a ...interface{}) error {
|
||||
return Error{err: fmt.Errorf(format, a...)}
|
||||
func Errorf(format, code string, a ...interface{}) error {
|
||||
return Error{err: fmt.Errorf(format, a...), code: code}
|
||||
}
|
||||
|
||||
// Unwrap the internal error.
|
||||
@@ -42,3 +43,11 @@ func (e Error) Error() string {
|
||||
}
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Code returns appropriate error code.
|
||||
func (e Error) Code() string {
|
||||
if e.code == "" {
|
||||
return "BadRequest"
|
||||
}
|
||||
return e.code
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ const (
|
||||
|
||||
// errors returned by tagging package
|
||||
var (
|
||||
ErrTooManyTags = Errorf("Cannot have more than 10 object tags")
|
||||
ErrInvalidTagKey = Errorf("The TagKey you have provided is invalid")
|
||||
ErrInvalidTagValue = Errorf("The TagValue you have provided is invalid")
|
||||
ErrInvalidTag = Errorf("Cannot provide multiple Tags with the same key")
|
||||
ErrTooManyTags = Errorf("Object tags cannot be greater than 10", "BadRequest")
|
||||
ErrInvalidTagKey = Errorf("The TagKey you have provided is invalid", "InvalidTag")
|
||||
ErrInvalidTagValue = Errorf("The TagValue you have provided is invalid", "InvalidTag")
|
||||
ErrInvalidTag = Errorf("Cannot provide multiple Tags with the same key", "InvalidTag")
|
||||
)
|
||||
|
||||
// Tagging - object tagging interface
|
||||
@@ -51,15 +51,15 @@ func (t Tagging) Validate() error {
|
||||
if len(t.TagSet.Tags) > maxTags {
|
||||
return ErrTooManyTags
|
||||
}
|
||||
if t.TagSet.ContainsDuplicateTag() {
|
||||
return ErrInvalidTag
|
||||
}
|
||||
// Validate all the rules in the tagging config
|
||||
for _, ts := range t.TagSet.Tags {
|
||||
if err := ts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if t.TagSet.ContainsDuplicateTag() {
|
||||
return ErrInvalidTag
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user