github.com/influxdata/influxdb/v2@v2.7.6/dbrp/error.go (about)

     1  package dbrp
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/influxdata/influxdb/v2/kit/platform/errors"
     7  	"github.com/influxdata/influxdb/v2/task/taskmodel"
     8  )
     9  
    10  var (
    11  	// ErrDBRPNotFound is used when the specified DBRP cannot be found.
    12  	ErrDBRPNotFound = &errors.Error{
    13  		Code: errors.ENotFound,
    14  		Msg:  "unable to find DBRP",
    15  	}
    16  
    17  	// ErrNotUniqueID is used when the ID of the DBRP is not unique.
    18  	ErrNotUniqueID = &errors.Error{
    19  		Code: errors.EConflict,
    20  		Msg:  "ID already exists",
    21  	}
    22  
    23  	// ErrFailureGeneratingID occurs ony when the random number generator
    24  	// cannot generate an ID in MaxIDGenerationN times.
    25  	ErrFailureGeneratingID = &errors.Error{
    26  		Code: errors.EInternal,
    27  		Msg:  "unable to generate valid id",
    28  	}
    29  
    30  	ErrNoOrgProvided = &errors.Error{
    31  		Code: errors.EInvalid,
    32  		Msg:  "either 'org' or 'orgID' must be provided",
    33  	}
    34  )
    35  
    36  // ErrOrgNotFound returns a more informative error about a 404 on org name.
    37  func ErrOrgNotFound(org string) error {
    38  	return &errors.Error{
    39  		Code: errors.ENotFound,
    40  		Msg:  fmt.Sprintf("invalid org %q", org),
    41  		Err:  taskmodel.ErrOrgNotFound,
    42  	}
    43  }
    44  
    45  // ErrInvalidOrgID returns a more informative error about a failure
    46  // to decode an organization ID.
    47  func ErrInvalidOrgID(id string, err error) error {
    48  	return &errors.Error{
    49  		Code: errors.EInvalid,
    50  		Msg:  fmt.Sprintf("invalid org ID %q", id),
    51  		Err:  err,
    52  	}
    53  }
    54  
    55  // ErrInvalidBucketID returns a more informative error about a failure
    56  // to decode a bucket ID.
    57  func ErrInvalidBucketID(id string, err error) error {
    58  	return &errors.Error{
    59  		Code: errors.EInvalid,
    60  		Msg:  fmt.Sprintf("invalid bucket ID %q", id),
    61  		Err:  err,
    62  	}
    63  }
    64  
    65  // ErrInvalidDBRPID is used when the ID of the DBRP cannot be encoded.
    66  func ErrInvalidDBRPID(id string, err error) error {
    67  	return &errors.Error{
    68  		Code: errors.EInvalid,
    69  		Msg:  fmt.Sprintf("invalid DBRP ID %q", id),
    70  		Err:  err,
    71  	}
    72  }
    73  
    74  // ErrInvalidDBRP is used when a service was provided an invalid DBRP.
    75  func ErrInvalidDBRP(err error) *errors.Error {
    76  	return &errors.Error{
    77  		Code: errors.EInvalid,
    78  		Msg:  "DBRP provided is invalid",
    79  		Err:  err,
    80  	}
    81  }
    82  
    83  // ErrInternalService is used when the error comes from an internal system.
    84  func ErrInternalService(err error) *errors.Error {
    85  	return &errors.Error{
    86  		Code: errors.EInternal,
    87  		Err:  err,
    88  	}
    89  }
    90  
    91  // ErrDBRPAlreadyExists is used when there is a conflict in creating a new DBRP.
    92  func ErrDBRPAlreadyExists(msg string) *errors.Error {
    93  	if msg == "" {
    94  		msg = "DBRP already exists"
    95  	}
    96  	return &errors.Error{
    97  		Code: errors.EConflict,
    98  		Msg:  msg,
    99  	}
   100  }