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

     1  /*
     2   * MinIO Cloud Storage, (C) 2018 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 event
    18  
    19  import (
    20  	"encoding/xml"
    21  	"fmt"
    22  )
    23  
    24  // IsEventError - checks whether given error is event error or not.
    25  func IsEventError(err error) bool {
    26  	switch err.(type) {
    27  	case ErrInvalidFilterName, *ErrInvalidFilterName:
    28  		return true
    29  	case ErrFilterNamePrefix, *ErrFilterNamePrefix:
    30  		return true
    31  	case ErrFilterNameSuffix, *ErrFilterNameSuffix:
    32  		return true
    33  	case ErrInvalidFilterValue, *ErrInvalidFilterValue:
    34  		return true
    35  	case ErrDuplicateEventName, *ErrDuplicateEventName:
    36  		return true
    37  	case ErrUnsupportedConfiguration, *ErrUnsupportedConfiguration:
    38  		return true
    39  	case ErrDuplicateQueueConfiguration, *ErrDuplicateQueueConfiguration:
    40  		return true
    41  	case ErrUnknownRegion, *ErrUnknownRegion:
    42  		return true
    43  	case ErrARNNotFound, *ErrARNNotFound:
    44  		return true
    45  	case ErrInvalidARN, *ErrInvalidARN:
    46  		return true
    47  	case ErrInvalidEventName, *ErrInvalidEventName:
    48  		return true
    49  	}
    50  
    51  	return false
    52  }
    53  
    54  // ErrInvalidFilterName - invalid filter name error.
    55  type ErrInvalidFilterName struct {
    56  	FilterName string
    57  }
    58  
    59  func (err ErrInvalidFilterName) Error() string {
    60  	return fmt.Sprintf("invalid filter name '%v'", err.FilterName)
    61  }
    62  
    63  // ErrFilterNamePrefix - more than one prefix usage error.
    64  type ErrFilterNamePrefix struct{}
    65  
    66  func (err ErrFilterNamePrefix) Error() string {
    67  	return "more than one prefix in filter rule"
    68  }
    69  
    70  // ErrFilterNameSuffix - more than one suffix usage error.
    71  type ErrFilterNameSuffix struct{}
    72  
    73  func (err ErrFilterNameSuffix) Error() string {
    74  	return "more than one suffix in filter rule"
    75  }
    76  
    77  // ErrInvalidFilterValue - invalid filter value error.
    78  type ErrInvalidFilterValue struct {
    79  	FilterValue string
    80  }
    81  
    82  func (err ErrInvalidFilterValue) Error() string {
    83  	return fmt.Sprintf("invalid filter value '%v'", err.FilterValue)
    84  }
    85  
    86  // ErrDuplicateEventName - duplicate event name error.
    87  type ErrDuplicateEventName struct {
    88  	EventName Name
    89  }
    90  
    91  func (err ErrDuplicateEventName) Error() string {
    92  	return fmt.Sprintf("duplicate event name '%v' found", err.EventName)
    93  }
    94  
    95  // ErrUnsupportedConfiguration - unsupported configuration error.
    96  type ErrUnsupportedConfiguration struct{}
    97  
    98  func (err ErrUnsupportedConfiguration) Error() string {
    99  	return "topic or cloud function configuration is not supported"
   100  }
   101  
   102  // ErrDuplicateQueueConfiguration - duplicate queue configuration error.
   103  type ErrDuplicateQueueConfiguration struct {
   104  	Queue Queue
   105  }
   106  
   107  func (err ErrDuplicateQueueConfiguration) Error() string {
   108  	var message string
   109  	if data, xerr := xml.Marshal(err.Queue); xerr != nil {
   110  		message = fmt.Sprintf("%+v", err.Queue)
   111  	} else {
   112  		message = string(data)
   113  	}
   114  
   115  	return fmt.Sprintf("duplicate queue configuration %v", message)
   116  }
   117  
   118  // ErrUnknownRegion - unknown region error.
   119  type ErrUnknownRegion struct {
   120  	Region string
   121  }
   122  
   123  func (err ErrUnknownRegion) Error() string {
   124  	return fmt.Sprintf("unknown region '%v'", err.Region)
   125  }
   126  
   127  // ErrARNNotFound - ARN not found error.
   128  type ErrARNNotFound struct {
   129  	ARN ARN
   130  }
   131  
   132  func (err ErrARNNotFound) Error() string {
   133  	return fmt.Sprintf("ARN '%v' not found", err.ARN)
   134  }
   135  
   136  // ErrInvalidARN - invalid ARN error.
   137  type ErrInvalidARN struct {
   138  	ARN string
   139  }
   140  
   141  func (err ErrInvalidARN) Error() string {
   142  	return fmt.Sprintf("invalid ARN '%v'", err.ARN)
   143  }
   144  
   145  // ErrInvalidEventName - invalid event name error.
   146  type ErrInvalidEventName struct {
   147  	Name string
   148  }
   149  
   150  func (err ErrInvalidEventName) Error() string {
   151  	return fmt.Sprintf("invalid event name '%v'", err.Name)
   152  }