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.

530 lines
14 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
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 ErrWikiAlreadyExist struct {
  92. Title string
  93. }
  94. func IsErrWikiAlreadyExist(err error) bool {
  95. _, ok := err.(ErrWikiAlreadyExist)
  96. return ok
  97. }
  98. func (err ErrWikiAlreadyExist) Error() string {
  99. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  100. }
  101. // __________ ___. .__ .__ ____ __.
  102. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  103. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  104. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  105. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  106. // \/ \/ \/ \/\/
  107. type ErrKeyUnableVerify struct {
  108. Result string
  109. }
  110. func IsErrKeyUnableVerify(err error) bool {
  111. _, ok := err.(ErrKeyUnableVerify)
  112. return ok
  113. }
  114. func (err ErrKeyUnableVerify) Error() string {
  115. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  116. }
  117. type ErrKeyNotExist struct {
  118. ID int64
  119. }
  120. func IsErrKeyNotExist(err error) bool {
  121. _, ok := err.(ErrKeyNotExist)
  122. return ok
  123. }
  124. func (err ErrKeyNotExist) Error() string {
  125. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  126. }
  127. type ErrKeyAlreadyExist struct {
  128. OwnerID int64
  129. Content string
  130. }
  131. func IsErrKeyAlreadyExist(err error) bool {
  132. _, ok := err.(ErrKeyAlreadyExist)
  133. return ok
  134. }
  135. func (err ErrKeyAlreadyExist) Error() string {
  136. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  137. }
  138. type ErrKeyNameAlreadyUsed struct {
  139. OwnerID int64
  140. Name string
  141. }
  142. func IsErrKeyNameAlreadyUsed(err error) bool {
  143. _, ok := err.(ErrKeyNameAlreadyUsed)
  144. return ok
  145. }
  146. func (err ErrKeyNameAlreadyUsed) Error() string {
  147. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  148. }
  149. type ErrKeyAccessDenied struct {
  150. UserID int64
  151. KeyID int64
  152. Note string
  153. }
  154. func IsErrKeyAccessDenied(err error) bool {
  155. _, ok := err.(ErrKeyAccessDenied)
  156. return ok
  157. }
  158. func (err ErrKeyAccessDenied) Error() string {
  159. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  160. err.UserID, err.KeyID, err.Note)
  161. }
  162. type ErrDeployKeyNotExist struct {
  163. ID int64
  164. KeyID int64
  165. RepoID int64
  166. }
  167. func IsErrDeployKeyNotExist(err error) bool {
  168. _, ok := err.(ErrDeployKeyNotExist)
  169. return ok
  170. }
  171. func (err ErrDeployKeyNotExist) Error() string {
  172. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  173. }
  174. type ErrDeployKeyAlreadyExist struct {
  175. KeyID int64
  176. RepoID int64
  177. }
  178. func IsErrDeployKeyAlreadyExist(err error) bool {
  179. _, ok := err.(ErrDeployKeyAlreadyExist)
  180. return ok
  181. }
  182. func (err ErrDeployKeyAlreadyExist) Error() string {
  183. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  184. }
  185. type ErrDeployKeyNameAlreadyUsed struct {
  186. RepoID int64
  187. Name string
  188. }
  189. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  190. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  191. return ok
  192. }
  193. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  194. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  195. }
  196. // _____ ___________ __
  197. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  198. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  199. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  200. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  201. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  202. type ErrAccessTokenNotExist struct {
  203. SHA string
  204. }
  205. func IsErrAccessTokenNotExist(err error) bool {
  206. _, ok := err.(ErrAccessTokenNotExist)
  207. return ok
  208. }
  209. func (err ErrAccessTokenNotExist) Error() string {
  210. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  211. }
  212. // ________ .__ __ .__
  213. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  214. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  215. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  216. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  217. // \/ /_____/ \/ \/ \/ \/ \/
  218. type ErrLastOrgOwner struct {
  219. UID int64
  220. }
  221. func IsErrLastOrgOwner(err error) bool {
  222. _, ok := err.(ErrLastOrgOwner)
  223. return ok
  224. }
  225. func (err ErrLastOrgOwner) Error() string {
  226. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  227. }
  228. // __________ .__ __
  229. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  230. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  231. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  232. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  233. // \/ \/|__| \/ \/
  234. type ErrRepoNotExist struct {
  235. ID int64
  236. UID int64
  237. Name string
  238. }
  239. func IsErrRepoNotExist(err error) bool {
  240. _, ok := err.(ErrRepoNotExist)
  241. return ok
  242. }
  243. func (err ErrRepoNotExist) Error() string {
  244. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  245. }
  246. type ErrRepoAlreadyExist struct {
  247. Uname string
  248. Name string
  249. }
  250. func IsErrRepoAlreadyExist(err error) bool {
  251. _, ok := err.(ErrRepoAlreadyExist)
  252. return ok
  253. }
  254. func (err ErrRepoAlreadyExist) Error() string {
  255. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  256. }
  257. type ErrInvalidCloneAddr struct {
  258. IsURLError bool
  259. IsInvalidPath bool
  260. IsPermissionDenied bool
  261. }
  262. func IsErrInvalidCloneAddr(err error) bool {
  263. _, ok := err.(ErrInvalidCloneAddr)
  264. return ok
  265. }
  266. func (err ErrInvalidCloneAddr) Error() string {
  267. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  268. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  269. }
  270. type ErrUpdateTaskNotExist struct {
  271. UUID string
  272. }
  273. func IsErrUpdateTaskNotExist(err error) bool {
  274. _, ok := err.(ErrUpdateTaskNotExist)
  275. return ok
  276. }
  277. func (err ErrUpdateTaskNotExist) Error() string {
  278. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  279. }
  280. type ErrReleaseAlreadyExist struct {
  281. TagName string
  282. }
  283. func IsErrReleaseAlreadyExist(err error) bool {
  284. _, ok := err.(ErrReleaseAlreadyExist)
  285. return ok
  286. }
  287. func (err ErrReleaseAlreadyExist) Error() string {
  288. return fmt.Sprintf("Release tag already exist [tag_name: %s]", err.TagName)
  289. }
  290. type ErrReleaseNotExist struct {
  291. ID int64
  292. TagName string
  293. }
  294. func IsErrReleaseNotExist(err error) bool {
  295. _, ok := err.(ErrReleaseNotExist)
  296. return ok
  297. }
  298. func (err ErrReleaseNotExist) Error() string {
  299. return fmt.Sprintf("Release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  300. }
  301. // __ __ ___. .__ __
  302. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  303. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  304. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  305. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  306. // \/ \/ \/ \/ \/
  307. type ErrWebhookNotExist struct {
  308. ID int64
  309. }
  310. func IsErrWebhookNotExist(err error) bool {
  311. _, ok := err.(ErrWebhookNotExist)
  312. return ok
  313. }
  314. func (err ErrWebhookNotExist) Error() string {
  315. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  316. }
  317. // .___
  318. // | | ______ ________ __ ____
  319. // | |/ ___// ___/ | \_/ __ \
  320. // | |\___ \ \___ \| | /\ ___/
  321. // |___/____ >____ >____/ \___ >
  322. // \/ \/ \/
  323. type ErrIssueNotExist struct {
  324. ID int64
  325. RepoID int64
  326. Index int64
  327. }
  328. func IsErrIssueNotExist(err error) bool {
  329. _, ok := err.(ErrIssueNotExist)
  330. return ok
  331. }
  332. func (err ErrIssueNotExist) Error() string {
  333. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  334. }
  335. // __________ .__ .__ __________ __
  336. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  337. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  338. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  339. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  340. // \/ \/ |__| \/ \/
  341. type ErrPullRequestNotExist struct {
  342. ID int64
  343. IssueID int64
  344. HeadRepoID int64
  345. BaseRepoID int64
  346. HeadBarcnh string
  347. BaseBranch string
  348. }
  349. func IsErrPullRequestNotExist(err error) bool {
  350. _, ok := err.(ErrPullRequestNotExist)
  351. return ok
  352. }
  353. func (err ErrPullRequestNotExist) Error() string {
  354. 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]",
  355. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
  356. }
  357. // _________ __
  358. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  359. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  360. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  361. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  362. // \/ \/ \/ \/ \/
  363. type ErrCommentNotExist struct {
  364. ID int64
  365. }
  366. func IsErrCommentNotExist(err error) bool {
  367. _, ok := err.(ErrCommentNotExist)
  368. return ok
  369. }
  370. func (err ErrCommentNotExist) Error() string {
  371. return fmt.Sprintf("comment does not exist [id: %d]", err.ID)
  372. }
  373. // .____ ___. .__
  374. // | | _____ \_ |__ ____ | |
  375. // | | \__ \ | __ \_/ __ \| |
  376. // | |___ / __ \| \_\ \ ___/| |__
  377. // |_______ (____ /___ /\___ >____/
  378. // \/ \/ \/ \/
  379. type ErrLabelNotExist struct {
  380. ID int64
  381. }
  382. func IsErrLabelNotExist(err error) bool {
  383. _, ok := err.(ErrLabelNotExist)
  384. return ok
  385. }
  386. func (err ErrLabelNotExist) Error() string {
  387. return fmt.Sprintf("label does not exist [id: %d]", err.ID)
  388. }
  389. // _____ .__.__ __
  390. // / \ |__| | ____ _______/ |_ ____ ____ ____
  391. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  392. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  393. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  394. // \/ \/ \/ \/ \/
  395. type ErrMilestoneNotExist struct {
  396. ID int64
  397. RepoID int64
  398. }
  399. func IsErrMilestoneNotExist(err error) bool {
  400. _, ok := err.(ErrMilestoneNotExist)
  401. return ok
  402. }
  403. func (err ErrMilestoneNotExist) Error() string {
  404. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  405. }
  406. // _____ __ __ .__ __
  407. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  408. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  409. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  410. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  411. // \/ \/ \/ \/ \/ \/ \/
  412. type ErrAttachmentNotExist struct {
  413. ID int64
  414. UUID string
  415. }
  416. func IsErrAttachmentNotExist(err error) bool {
  417. _, ok := err.(ErrAttachmentNotExist)
  418. return ok
  419. }
  420. func (err ErrAttachmentNotExist) Error() string {
  421. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  422. }