error.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. )
  8. type ErrNameReserved struct {
  9. Name string
  10. }
  11. func IsErrNameReserved(err error) bool {
  12. _, ok := err.(ErrNameReserved)
  13. return ok
  14. }
  15. func (err ErrNameReserved) Error() string {
  16. return fmt.Sprintf("name is reserved: [name: %s]", err.Name)
  17. }
  18. type ErrNamePatternNotAllowed struct {
  19. Pattern string
  20. }
  21. func IsErrNamePatternNotAllowed(err error) bool {
  22. _, ok := err.(ErrNamePatternNotAllowed)
  23. return ok
  24. }
  25. func (err ErrNamePatternNotAllowed) Error() string {
  26. return fmt.Sprintf("name pattern is not allowed: [pattern: %s]", err.Pattern)
  27. }
  28. // ____ ___
  29. // | | \______ ___________
  30. // | | / ___// __ \_ __ \
  31. // | | /\___ \\ ___/| | \/
  32. // |______//____ >\___ >__|
  33. // \/ \/
  34. type ErrUserAlreadyExist struct {
  35. Name string
  36. }
  37. func IsErrUserAlreadyExist(err error) bool {
  38. _, ok := err.(ErrUserAlreadyExist)
  39. return ok
  40. }
  41. func (err ErrUserAlreadyExist) Error() string {
  42. return fmt.Sprintf("user already exists: [name: %s]", err.Name)
  43. }
  44. type ErrEmailAlreadyUsed struct {
  45. Email string
  46. }
  47. func IsErrEmailAlreadyUsed(err error) bool {
  48. _, ok := err.(ErrEmailAlreadyUsed)
  49. return ok
  50. }
  51. func (err ErrEmailAlreadyUsed) Error() string {
  52. return fmt.Sprintf("e-mail has been used: [email: %s]", err.Email)
  53. }
  54. type ErrUserOwnRepos struct {
  55. UID int64
  56. }
  57. func IsErrUserOwnRepos(err error) bool {
  58. _, ok := err.(ErrUserOwnRepos)
  59. return ok
  60. }
  61. func (err ErrUserOwnRepos) Error() string {
  62. return fmt.Sprintf("user still has ownership of repositories: [uid: %d]", err.UID)
  63. }
  64. type ErrUserHasOrgs struct {
  65. UID int64
  66. }
  67. func IsErrUserHasOrgs(err error) bool {
  68. _, ok := err.(ErrUserHasOrgs)
  69. return ok
  70. }
  71. func (err ErrUserHasOrgs) Error() string {
  72. return fmt.Sprintf("user still has membership of organizations: [uid: %d]", err.UID)
  73. }
  74. // ________ .__ __ .__
  75. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  76. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  77. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  78. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  79. // \/ /_____/ \/ \/ \/ \/ \/
  80. type ErrLastOrgOwner struct {
  81. UID int64
  82. }
  83. func IsErrLastOrgOwner(err error) bool {
  84. _, ok := err.(ErrLastOrgOwner)
  85. return ok
  86. }
  87. func (err ErrLastOrgOwner) Error() string {
  88. return fmt.Sprintf("user is the last member of owner team: [uid: %d]", err.UID)
  89. }
  90. // __________ .__ __
  91. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  92. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  93. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  94. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  95. // \/ \/|__| \/ \/
  96. type ErrRepoNotExist struct {
  97. ID int64
  98. UID int64
  99. Name string
  100. }
  101. func IsErrRepoNotExist(err error) bool {
  102. _, ok := err.(ErrRepoNotExist)
  103. return ok
  104. }
  105. func (err ErrRepoNotExist) Error() string {
  106. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  107. }