github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/event/errors.go (about)

     1  // Copyright (c) 2015-2021 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package event
    19  
    20  import (
    21  	"encoding/xml"
    22  	"fmt"
    23  )
    24  
    25  // IsEventError - checks whether given error is event error or not.
    26  func IsEventError(err error) bool {
    27  	switch err.(type) {
    28  	case ErrInvalidFilterName, *ErrInvalidFilterName:
    29  		return true
    30  	case ErrFilterNamePrefix, *ErrFilterNamePrefix:
    31  		return true
    32  	case ErrFilterNameSuffix, *ErrFilterNameSuffix:
    33  		return true
    34  	case ErrInvalidFilterValue, *ErrInvalidFilterValue:
    35  		return true
    36  	case ErrDuplicateEventName, *ErrDuplicateEventName:
    37  		return true
    38  	case ErrUnsupportedConfiguration, *ErrUnsupportedConfiguration:
    39  		return true
    40  	case ErrDuplicateQueueConfiguration, *ErrDuplicateQueueConfiguration:
    41  		return true
    42  	case ErrUnknownRegion, *ErrUnknownRegion:
    43  		return true
    44  	case ErrARNNotFound, *ErrARNNotFound:
    45  		return true
    46  	case ErrInvalidARN, *ErrInvalidARN:
    47  		return true
    48  	case ErrInvalidEventName, *ErrInvalidEventName:
    49  		return true
    50  	}
    51  
    52  	return false
    53  }
    54  
    55  // ErrInvalidFilterName - invalid filter name error.
    56  type ErrInvalidFilterName struct {
    57  	FilterName string
    58  }
    59  
    60  func (err ErrInvalidFilterName) Error() string {
    61  	return fmt.Sprintf("invalid filter name '%v'", err.FilterName)
    62  }
    63  
    64  // ErrFilterNamePrefix - more than one prefix usage error.
    65  type ErrFilterNamePrefix struct{}
    66  
    67  func (err ErrFilterNamePrefix) Error() string {
    68  	return "more than one prefix in filter rule"
    69  }
    70  
    71  // ErrFilterNameSuffix - more than one suffix usage error.
    72  type ErrFilterNameSuffix struct{}
    73  
    74  func (err ErrFilterNameSuffix) Error() string {
    75  	return "more than one suffix in filter rule"
    76  }
    77  
    78  // ErrInvalidFilterValue - invalid filter value error.
    79  type ErrInvalidFilterValue struct {
    80  	FilterValue string
    81  }
    82  
    83  func (err ErrInvalidFilterValue) Error() string {
    84  	return fmt.Sprintf("invalid filter value '%v'", err.FilterValue)
    85  }
    86  
    87  // ErrDuplicateEventName - duplicate event name error.
    88  type ErrDuplicateEventName struct {
    89  	EventName Name
    90  }
    91  
    92  func (err ErrDuplicateEventName) Error() string {
    93  	return fmt.Sprintf("duplicate event name '%v' found", err.EventName)
    94  }
    95  
    96  // ErrUnsupportedConfiguration - unsupported configuration error.
    97  type ErrUnsupportedConfiguration struct{}
    98  
    99  func (err ErrUnsupportedConfiguration) Error() string {
   100  	return "topic or cloud function configuration is not supported"
   101  }
   102  
   103  // ErrDuplicateQueueConfiguration - duplicate queue configuration error.
   104  type ErrDuplicateQueueConfiguration struct {
   105  	Queue Queue
   106  }
   107  
   108  func (err ErrDuplicateQueueConfiguration) Error() string {
   109  	var message string
   110  	if data, xerr := xml.Marshal(err.Queue); xerr != nil {
   111  		message = fmt.Sprintf("%+v", err.Queue)
   112  	} else {
   113  		message = string(data)
   114  	}
   115  
   116  	return fmt.Sprintf("duplicate queue configuration %v", message)
   117  }
   118  
   119  // ErrUnknownRegion - unknown region error.
   120  type ErrUnknownRegion struct {
   121  	Region string
   122  }
   123  
   124  func (err ErrUnknownRegion) Error() string {
   125  	return fmt.Sprintf("unknown region '%v'", err.Region)
   126  }
   127  
   128  // ErrARNNotFound - ARN not found error.
   129  type ErrARNNotFound struct {
   130  	ARN ARN
   131  }
   132  
   133  func (err ErrARNNotFound) Error() string {
   134  	return fmt.Sprintf("ARN '%v' not found", err.ARN)
   135  }
   136  
   137  // ErrInvalidARN - invalid ARN error.
   138  type ErrInvalidARN struct {
   139  	ARN string
   140  }
   141  
   142  func (err ErrInvalidARN) Error() string {
   143  	return fmt.Sprintf("invalid ARN '%v'", err.ARN)
   144  }
   145  
   146  // ErrInvalidEventName - invalid event name error.
   147  type ErrInvalidEventName struct {
   148  	Name string
   149  }
   150  
   151  func (err ErrInvalidEventName) Error() string {
   152  	return fmt.Sprintf("invalid event name '%v'", err.Name)
   153  }