errors.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package jsonpatch
  2. import "fmt"
  3. // AccumulatedCopySizeError is an error type returned when the accumulated size
  4. // increase caused by copy operations in a patch operation has exceeded the
  5. // limit.
  6. type AccumulatedCopySizeError struct {
  7. limit int64
  8. accumulated int64
  9. }
  10. // NewAccumulatedCopySizeError returns an AccumulatedCopySizeError.
  11. func NewAccumulatedCopySizeError(l, a int64) *AccumulatedCopySizeError {
  12. return &AccumulatedCopySizeError{limit: l, accumulated: a}
  13. }
  14. // Error implements the error interface.
  15. func (a *AccumulatedCopySizeError) Error() string {
  16. return fmt.Sprintf("Unable to complete the copy, the accumulated size increase of copy is %d, exceeding the limit %d", a.accumulated, a.limit)
  17. }
  18. // ArraySizeError is an error type returned when the array size has exceeded
  19. // the limit.
  20. type ArraySizeError struct {
  21. limit int
  22. size int
  23. }
  24. // NewArraySizeError returns an ArraySizeError.
  25. func NewArraySizeError(l, s int) *ArraySizeError {
  26. return &ArraySizeError{limit: l, size: s}
  27. }
  28. // Error implements the error interface.
  29. func (a *ArraySizeError) Error() string {
  30. return fmt.Sprintf("Unable to create array of size %d, limit is %d", a.size, a.limit)
  31. }