You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

439 lines
12 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  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 ErrAccessTokenNotExist struct {
  152. SHA string
  153. }
  154. func IsErrAccessTokenNotExist(err error) bool {
  155. _, ok := err.(ErrAccessTokenNotExist)
  156. return ok
  157. }
  158. func (err ErrAccessTokenNotExist) Error() string {
  159. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  160. }
  161. // ________ .__ __ .__
  162. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  163. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  164. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  165. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  166. // \/ /_____/ \/ \/ \/ \/ \/
  167. type ErrLastOrgOwner struct {
  168. UID int64
  169. }
  170. func IsErrLastOrgOwner(err error) bool {
  171. _, ok := err.(ErrLastOrgOwner)
  172. return ok
  173. }
  174. func (err ErrLastOrgOwner) Error() string {
  175. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  176. }
  177. // __________ .__ __
  178. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  179. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  180. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  181. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  182. // \/ \/|__| \/ \/
  183. type ErrRepoNotExist struct {
  184. ID int64
  185. UID int64
  186. Name string
  187. }
  188. func IsErrRepoNotExist(err error) bool {
  189. _, ok := err.(ErrRepoNotExist)
  190. return ok
  191. }
  192. func (err ErrRepoNotExist) Error() string {
  193. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  194. }
  195. type ErrRepoAlreadyExist struct {
  196. Uname string
  197. Name string
  198. }
  199. func IsErrRepoAlreadyExist(err error) bool {
  200. _, ok := err.(ErrRepoAlreadyExist)
  201. return ok
  202. }
  203. func (err ErrRepoAlreadyExist) Error() string {
  204. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  205. }
  206. type ErrInvalidCloneAddr struct {
  207. IsURLError bool
  208. IsInvalidPath bool
  209. IsPermissionDenied bool
  210. }
  211. func IsErrInvalidCloneAddr(err error) bool {
  212. _, ok := err.(ErrInvalidCloneAddr)
  213. return ok
  214. }
  215. func (err ErrInvalidCloneAddr) Error() string {
  216. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  217. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  218. }
  219. type ErrUpdateTaskNotExist struct {
  220. UUID string
  221. }
  222. func IsErrUpdateTaskNotExist(err error) bool {
  223. _, ok := err.(ErrUpdateTaskNotExist)
  224. return ok
  225. }
  226. func (err ErrUpdateTaskNotExist) Error() string {
  227. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  228. }
  229. // __ __ ___. .__ __
  230. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  231. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  232. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  233. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  234. // \/ \/ \/ \/ \/
  235. type ErrWebhookNotExist struct {
  236. ID int64
  237. }
  238. func IsErrWebhookNotExist(err error) bool {
  239. _, ok := err.(ErrWebhookNotExist)
  240. return ok
  241. }
  242. func (err ErrWebhookNotExist) Error() string {
  243. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  244. }
  245. // .___
  246. // | | ______ ________ __ ____
  247. // | |/ ___// ___/ | \_/ __ \
  248. // | |\___ \ \___ \| | /\ ___/
  249. // |___/____ >____ >____/ \___ >
  250. // \/ \/ \/
  251. type ErrIssueNotExist struct {
  252. ID int64
  253. RepoID int64
  254. Index int64
  255. }
  256. func IsErrIssueNotExist(err error) bool {
  257. _, ok := err.(ErrIssueNotExist)
  258. return ok
  259. }
  260. func (err ErrIssueNotExist) Error() string {
  261. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  262. }
  263. // __________ .__ .__ __________ __
  264. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  265. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  266. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  267. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  268. // \/ \/ |__| \/ \/
  269. type ErrPullRequestNotExist struct {
  270. ID int64
  271. IssueID int64
  272. HeadRepoID int64
  273. BaseRepoID int64
  274. HeadBarcnh string
  275. BaseBranch string
  276. }
  277. func IsErrPullRequestNotExist(err error) bool {
  278. _, ok := err.(ErrPullRequestNotExist)
  279. return ok
  280. }
  281. func (err ErrPullRequestNotExist) Error() string {
  282. return fmt.Sprintf("pull request does not exist [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
  283. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
  284. }
  285. // _________ __
  286. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  287. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  288. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  289. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  290. // \/ \/ \/ \/ \/
  291. type ErrCommentNotExist struct {
  292. ID int64
  293. }
  294. func IsErrCommentNotExist(err error) bool {
  295. _, ok := err.(ErrCommentNotExist)
  296. return ok
  297. }
  298. func (err ErrCommentNotExist) Error() string {
  299. return fmt.Sprintf("comment does not exist [id: %d]", err.ID)
  300. }
  301. // .____ ___. .__
  302. // | | _____ \_ |__ ____ | |
  303. // | | \__ \ | __ \_/ __ \| |
  304. // | |___ / __ \| \_\ \ ___/| |__
  305. // |_______ (____ /___ /\___ >____/
  306. // \/ \/ \/ \/
  307. type ErrLabelNotExist struct {
  308. ID int64
  309. }
  310. func IsErrLabelNotExist(err error) bool {
  311. _, ok := err.(ErrLabelNotExist)
  312. return ok
  313. }
  314. func (err ErrLabelNotExist) Error() string {
  315. return fmt.Sprintf("label does not exist [id: %d]", err.ID)
  316. }
  317. // _____ .__.__ __
  318. // / \ |__| | ____ _______/ |_ ____ ____ ____
  319. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  320. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  321. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  322. // \/ \/ \/ \/ \/
  323. type ErrMilestoneNotExist struct {
  324. ID int64
  325. RepoID int64
  326. }
  327. func IsErrMilestoneNotExist(err error) bool {
  328. _, ok := err.(ErrMilestoneNotExist)
  329. return ok
  330. }
  331. func (err ErrMilestoneNotExist) Error() string {
  332. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  333. }
  334. // _____ __ __ .__ __
  335. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  336. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  337. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  338. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  339. // \/ \/ \/ \/ \/ \/ \/
  340. type ErrAttachmentNotExist struct {
  341. ID int64
  342. UUID string
  343. }
  344. func IsErrAttachmentNotExist(err error) bool {
  345. _, ok := err.(ErrAttachmentNotExist)
  346. return ok
  347. }
  348. func (err ErrAttachmentNotExist) Error() string {
  349. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  350. }