github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/store/errors.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package store 5 6 import ( 7 "fmt" 8 ) 9 10 // ErrInvalidInput indicates an error that has occurred due to an invalid input. 11 type ErrInvalidInput struct { 12 Entity string // The entity which was sent as the input. 13 Field string // The field of the entity which was invalid. 14 Value interface{} // The actual value of the field. 15 } 16 17 func NewErrInvalidInput(entity, field string, value interface{}) *ErrInvalidInput { 18 return &ErrInvalidInput{ 19 Entity: entity, 20 Field: field, 21 Value: value, 22 } 23 } 24 25 func (e *ErrInvalidInput) Error() string { 26 return fmt.Sprintf("invalid input: entity: %s field: %s value: %s", e.Entity, e.Field, e.Value) 27 } 28 29 // ErrLimitExceeded indicates an error that has occurred because some value exceeded a limit. 30 type ErrLimitExceeded struct { 31 What string // What was the object that exceeded. 32 Count int // The value of the object. 33 meta string // Any additional metadata. 34 } 35 36 func NewErrLimitExceeded(what string, count int, meta string) *ErrLimitExceeded { 37 return &ErrLimitExceeded{ 38 What: what, 39 Count: count, 40 meta: meta, 41 } 42 } 43 44 func (e *ErrLimitExceeded) Error() string { 45 return fmt.Sprintf("limit exceeded: what: %s count: %d metadata: %s", e.What, e.Count, e.meta) 46 } 47 48 // ErrConflict indicates a conflict that occurred. 49 type ErrConflict struct { 50 Resource string // The resource which created the conflict. 51 err error // Internal error. 52 meta string // Any additional metadata. 53 } 54 55 func NewErrConflict(resource string, err error, meta string) *ErrConflict { 56 return &ErrConflict{ 57 Resource: resource, 58 err: err, 59 meta: meta, 60 } 61 } 62 63 func (e *ErrConflict) Error() string { 64 msg := e.Resource + "exists " + e.meta 65 if e.err != nil { 66 msg += " " + e.err.Error() 67 } 68 return msg 69 } 70 71 func (e *ErrConflict) Unwrap() error { 72 return e.err 73 } 74 75 // ErrNotFound indicates that a resource was not found 76 type ErrNotFound struct { 77 resource string 78 Id string 79 } 80 81 func NewErrNotFound(resource, id string) *ErrNotFound { 82 return &ErrNotFound{ 83 resource: resource, 84 Id: id, 85 } 86 } 87 88 func (e *ErrNotFound) Error() string { 89 return "resource: " + e.resource + " id: " + e.Id 90 } 91 92 // ErrOutOfBounds indicates that the requested total numbers of rows 93 // was greater than the allowed limit. 94 type ErrOutOfBounds struct { 95 value int 96 } 97 98 func (e *ErrOutOfBounds) Error() string { 99 return fmt.Sprintf("invalid limit parameter: %d", e.value) 100 } 101 102 func NewErrOutOfBounds(value int) *ErrOutOfBounds { 103 return &ErrOutOfBounds{value: value} 104 } 105 106 // ErrNotImplemented indicates that some feature or requirement is not implemented yet. 107 type ErrNotImplemented struct { 108 detail string 109 } 110 111 func (e *ErrNotImplemented) Error() string { 112 return e.detail 113 } 114 115 func NewErrNotImplemented(detail string) *ErrNotImplemented { 116 return &ErrNotImplemented{detail: detail} 117 }