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.

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