error.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 ErrUserNotExist struct {
  45. UID int64
  46. Name string
  47. }
  48. func IsErrUserNotExist(err error) bool {
  49. _, ok := err.(ErrUserNotExist)
  50. return ok
  51. }
  52. func (err ErrUserNotExist) Error() string {
  53. return fmt.Sprintf("user does not exist: [uid: %d, name: %s]", err.UID, err.Name)
  54. }
  55. type ErrEmailAlreadyUsed struct {
  56. Email string
  57. }
  58. func IsErrEmailAlreadyUsed(err error) bool {
  59. _, ok := err.(ErrEmailAlreadyUsed)
  60. return ok
  61. }
  62. func (err ErrEmailAlreadyUsed) Error() string {
  63. return fmt.Sprintf("e-mail has been used: [email: %s]", err.Email)
  64. }
  65. type ErrUserOwnRepos struct {
  66. UID int64
  67. }
  68. func IsErrUserOwnRepos(err error) bool {
  69. _, ok := err.(ErrUserOwnRepos)
  70. return ok
  71. }
  72. func (err ErrUserOwnRepos) Error() string {
  73. return fmt.Sprintf("user still has ownership of repositories: [uid: %d]", err.UID)
  74. }
  75. type ErrUserHasOrgs struct {
  76. UID int64
  77. }
  78. func IsErrUserHasOrgs(err error) bool {
  79. _, ok := err.(ErrUserHasOrgs)
  80. return ok
  81. }
  82. func (err ErrUserHasOrgs) Error() string {
  83. return fmt.Sprintf("user still has membership of organizations: [uid: %d]", err.UID)
  84. }
  85. // __________ ___. .__ .__ ____ __.
  86. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  87. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  88. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  89. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  90. // \/ \/ \/ \/\/
  91. type ErrKeyNotExist struct {
  92. ID int64
  93. }
  94. func IsErrKeyNotExist(err error) bool {
  95. _, ok := err.(ErrKeyNotExist)
  96. return ok
  97. }
  98. func (err ErrKeyNotExist) Error() string {
  99. return fmt.Sprintf("public key does not exist: [id: %d]", err.ID)
  100. }
  101. type ErrKeyAlreadyExist struct {
  102. OwnerID int64
  103. Content string
  104. }
  105. func IsErrKeyAlreadyExist(err error) bool {
  106. _, ok := err.(ErrKeyAlreadyExist)
  107. return ok
  108. }
  109. func (err ErrKeyAlreadyExist) Error() string {
  110. return fmt.Sprintf("public key already exists: [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  111. }
  112. type ErrKeyNameAlreadyUsed struct {
  113. OwnerID int64
  114. Name string
  115. }
  116. func IsErrKeyNameAlreadyUsed(err error) bool {
  117. _, ok := err.(ErrKeyNameAlreadyUsed)
  118. return ok
  119. }
  120. func (err ErrKeyNameAlreadyUsed) Error() string {
  121. return fmt.Sprintf("public key already exists: [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  122. }
  123. type ErrDeployKeyAlreadyExist struct {
  124. KeyID int64
  125. RepoID int64
  126. }
  127. func IsErrDeployKeyAlreadyExist(err error) bool {
  128. _, ok := err.(ErrDeployKeyAlreadyExist)
  129. return ok
  130. }
  131. func (err ErrDeployKeyAlreadyExist) Error() string {
  132. return fmt.Sprintf("public key already exists: [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  133. }
  134. type ErrDeployKeyNameAlreadyUsed struct {
  135. RepoID int64
  136. Name string
  137. }
  138. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  139. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  140. return ok
  141. }
  142. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  143. return fmt.Sprintf("public key already exists: [repo_id: %d, name: %s]", err.RepoID, err.Name)
  144. }
  145. // ________ .__ __ .__
  146. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  147. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  148. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  149. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  150. // \/ /_____/ \/ \/ \/ \/ \/
  151. type ErrLastOrgOwner struct {
  152. UID int64
  153. }
  154. func IsErrLastOrgOwner(err error) bool {
  155. _, ok := err.(ErrLastOrgOwner)
  156. return ok
  157. }
  158. func (err ErrLastOrgOwner) Error() string {
  159. return fmt.Sprintf("user is the last member of owner team: [uid: %d]", err.UID)
  160. }
  161. // __________ .__ __
  162. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  163. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  164. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  165. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  166. // \/ \/|__| \/ \/
  167. type ErrRepoNotExist struct {
  168. ID int64
  169. UID int64
  170. Name string
  171. }
  172. func IsErrRepoNotExist(err error) bool {
  173. _, ok := err.(ErrRepoNotExist)
  174. return ok
  175. }
  176. func (err ErrRepoNotExist) Error() string {
  177. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  178. }
  179. type ErrRepoAlreadyExist struct {
  180. Uname string
  181. Name string
  182. }
  183. func IsErrRepoAlreadyExist(err error) bool {
  184. _, ok := err.(ErrRepoAlreadyExist)
  185. return ok
  186. }
  187. func (err ErrRepoAlreadyExist) Error() string {
  188. return fmt.Sprintf("repository already exists [uname: %d, name: %s]", err.Uname, err.Name)
  189. }
  190. // .___
  191. // | | ______ ________ __ ____
  192. // | |/ ___// ___/ | \_/ __ \
  193. // | |\___ \ \___ \| | /\ ___/
  194. // |___/____ >____ >____/ \___ >
  195. // \/ \/ \/
  196. type ErrIssueNotExist struct {
  197. ID int64
  198. RepoID int64
  199. Index int64
  200. }
  201. func IsErrIssueNotExist(err error) bool {
  202. _, ok := err.(ErrIssueNotExist)
  203. return ok
  204. }
  205. func (err ErrIssueNotExist) Error() string {
  206. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  207. }
  208. // _________ __
  209. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  210. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  211. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  212. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  213. // \/ \/ \/ \/ \/
  214. type ErrCommentNotExist struct {
  215. ID int64
  216. }
  217. func IsErrCommentNotExist(err error) bool {
  218. _, ok := err.(ErrCommentNotExist)
  219. return ok
  220. }
  221. func (err ErrCommentNotExist) Error() string {
  222. return fmt.Sprintf("comment does not exist [id: %d]", err.ID)
  223. }
  224. // .____ ___. .__
  225. // | | _____ \_ |__ ____ | |
  226. // | | \__ \ | __ \_/ __ \| |
  227. // | |___ / __ \| \_\ \ ___/| |__
  228. // |_______ (____ /___ /\___ >____/
  229. // \/ \/ \/ \/
  230. type ErrLabelNotExist struct {
  231. ID int64
  232. }
  233. func IsErrLabelNotExist(err error) bool {
  234. _, ok := err.(ErrLabelNotExist)
  235. return ok
  236. }
  237. func (err ErrLabelNotExist) Error() string {
  238. return fmt.Sprintf("label does not exist [id: %d]", err.ID)
  239. }
  240. // _____ .__.__ __
  241. // / \ |__| | ____ _______/ |_ ____ ____ ____
  242. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  243. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  244. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  245. // \/ \/ \/ \/ \/
  246. type ErrMilestoneNotExist struct {
  247. ID int64
  248. RepoID int64
  249. }
  250. func IsErrMilestoneNotExist(err error) bool {
  251. _, ok := err.(ErrMilestoneNotExist)
  252. return ok
  253. }
  254. func (err ErrMilestoneNotExist) Error() string {
  255. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  256. }
  257. // _____ __ __ .__ __
  258. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  259. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  260. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  261. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  262. // \/ \/ \/ \/ \/ \/ \/
  263. type ErrAttachmentNotExist struct {
  264. ID int64
  265. UUID string
  266. }
  267. func IsErrAttachmentNotExist(err error) bool {
  268. _, ok := err.(ErrAttachmentNotExist)
  269. return ok
  270. }
  271. func (err ErrAttachmentNotExist) Error() string {
  272. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  273. }